'Create master and register other servers.'

def testRegister(self):

    m = master.DataMaster(self.ports[0], self.mock_service)
    self.assertNotEqual(m, None)
    self.assertFalse(m.AllRegistered())
    servers = [None]
    for (i, port) in enumerate(self.ports):
        if (i == 0):
            continue
        self.assertFalse(m.AllRegistered())
        server = m.RegisterServer(self.host, port)
        servers.append(server)
        self.assertNotEqual(server, None)
        self.assertEqual(server.Address(), self.host)
        self.assertEqual(server.Port(), port)
        self.assertEqual(server.Index(), i)
    self.assertTrue(m.AllRegistered())
    self.assertFalse(m.RegisterServer(self.host, 7004))
    m.DeregisterServer(servers[1])
    self.assertFalse(m.AllRegistered())
    m.RegisterServer(servers[1].Address(), servers[1].Port())
    self.assertTrue(m.AllRegistered())
    for port in self.ports:
        for response_sequence in [[constants.RESPONSE_OK, constants.RESPONSE_SERVER_NOT_AUTHORIZED], [constants.RESPONSE_OK, constants.RESPONSE_SERVER_NOT_ALLOWED], [constants.RESPONSE_OK, constants.RESPONSE_NOT_MASTER_SERVER]]:
            response_mocks = []
            for response_status in response_sequence:
                response_mocks.append(MockResponse(response_status))
            pool_class = GetMockHTTPConnectionPoolClass(response_mocks)
            with libutils.Stubber(urllib3.connectionpool, 'HTTPConnectionPool', pool_class):
                m = data_server.StandardDataServer(port, data_server.DataServerHandler)
                m.handler_cls.NONCE_STORE = auth.NonceStore()
                self.assertRaises(errors.DataServerError, m._DoRegister)
                self.assertEqual(len(pool_class.requests), 2)
                self.assertTrue(pool_class.requests[1]['body'])
                rdf_data_server.DataStoreRegistrationRequest.FromSerializedString(pool_class.requests[1]['body'])
                self.assertEqual(pool_class.requests[0]['method'], 'POST')
                self.assertEqual(pool_class.requests[1]['method'], 'POST')
                self.assertEqual(pool_class.requests[0]['url'], '/server/handshake')
                self.assertEqual(pool_class.requests[1]['url'], '/server/register')
