def test_get_remote_connections(self, get_svc_ticket_success, _client_cls, _vim_client_cls): host = "mock_host" port = 8835 get_service_ticket_mock = MagicMock() if get_svc_ticket_success: get_service_ticket_mock.result = ServiceTicketResultCode.OK else: get_service_ticket_mock.result = ServiceTicketResultCode.NOT_FOUND instance = _client_cls.return_value instance.get_service_ticket.return_value = get_service_ticket_mock if get_svc_ticket_success: (agent_conn, vim_conn) = self.http_transferer._get_remote_connections( host, port) _client_cls.assert_called_once_with( "Host", Host.Client, host, port) instance.connect.assert_called_once_with() request = ServiceTicketRequest(service_type=ServiceType.VIM) instance.get_service_ticket.assert_called_once_with(request) _vim_client_cls.assert_called_once_with( host=host, ticket=get_service_ticket_mock.vim_ticket, auto_sync=False) self.assertEqual(agent_conn, instance) self.assertEqual(vim_conn, _vim_client_cls.return_value) else: self.assertRaises( ValueError, self.http_transferer._get_remote_connections, host, port)
def test_create_remote_vim_client(self, get_svc_ticket_success, _vim_client_cls): host = "mock_host" get_service_ticket_mock = MagicMock() if get_svc_ticket_success: get_service_ticket_mock.result = ServiceTicketResultCode.OK else: get_service_ticket_mock.result = ServiceTicketResultCode.NOT_FOUND agent_client = MagicMock() agent_client.get_service_ticket.return_value = get_service_ticket_mock if get_svc_ticket_success: vim_conn = self.http_transferer._create_remote_vim_client( agent_client, host) request = ServiceTicketRequest(service_type=ServiceType.VIM) agent_client.get_service_ticket.assert_called_once_with(request) _vim_client_cls.assert_called_once_with( host=host, ticket=get_service_ticket_mock.vim_ticket, auto_sync=False) self.assertEqual(vim_conn, _vim_client_cls.return_value) else: self.assertRaises(ValueError, self.http_transferer._create_remote_vim_client, agent_client, host)
def _get_nfc_ticket(self, remote_agent_client, datastore): request = ServiceTicketRequest(ServiceType.NFC, datastore) response = remote_agent_client.get_service_ticket(request) if response.result != ServiceTicketResultCode.OK: err_msg = "Get service ticket failed. Response = %s" % str( response) self._logger.error(err_msg) raise Exception(err_msg) return response.ticket
def _create_remote_vim_client(self, agent_client, host): request = ServiceTicketRequest(service_type=ServiceType.VIM) response = agent_client.get_service_ticket(request) if response.result != ServiceTicketResultCode.OK: self._logger.info("Get service ticket failed. Response = %s" % str(response)) raise ValueError("No ticket") vim_client = VimClient(host=host, ticket=response.vim_ticket, auto_sync=False) return vim_client
def _get_remote_connections(self, host, port): agent_client = DirectClient("Host", Host.Client, host, port) agent_client.connect() request = ServiceTicketRequest(service_type=ServiceType.VIM) response = agent_client.get_service_ticket(request) if response.result != ServiceTicketResultCode.OK: self._logger.info("Get service ticket failed. Response = %s" % str(response)) raise ValueError("No ticket") vim_client = VimClient( host=host, ticket=response.vim_ticket, auto_sync=False) return agent_client, vim_client
def test_get_nfc_ticket(self): request = ServiceTicketRequest( service_type=ServiceType.NFC, datastore_name=self.get_image_datastore()) response = self.host_client.get_service_ticket(request) assert_that(response.result, is_(ServiceTicketResultCode.OK)) ticket = response.ticket assert_that(ticket, not_none()) assert_that(ticket.port, is_(902)) assert_that(ticket.service_type, is_("nfc")) assert_that(ticket.session_id, not_none()) assert_that(ticket.ssl_thumbprint, not_none())
def get_service_instance(self): # create a connection to hostd. request = ServiceTicketRequest(ServiceType.VIM) response = self.host_client.get_service_ticket(request) self.assertEqual(response.result, ServiceTicketResultCode.OK) hostd_port = 443 vim_namespace = "vim25/5.0" stub = SoapStubAdapter(self.server, hostd_port, vim_namespace) si = vim.ServiceInstance("ServiceInstance", stub) si.RetrieveContent().sessionManager.CloneSession(response.vim_ticket) connect.SetSi(si) return si
def test_get_nfc_ticket_with_ds_id(self): datastores = self.vim_client.get_all_datastores() image_datastore = [ ds for ds in datastores if ds.name == self.get_image_datastore() ][0] request = ServiceTicketRequest(service_type=ServiceType.NFC, datastore_name=image_datastore.id) response = self.host_client.get_service_ticket(request) assert_that(response.result, is_(ServiceTicketResultCode.OK)) ticket = response.ticket assert_that(ticket, not_none()) assert_that(ticket.port, is_(902)) assert_that(ticket.service_type, is_("nfc")) assert_that(ticket.session_id, not_none()) assert_that(ticket.ssl_thumbprint, not_none())
def test_get_service_ticket_not_found(self): request = ServiceTicketRequest(ServiceType.NFC, 'not_existed') response = self.host_client.get_service_ticket(request) assert_that(response.result, is_(ServiceTicketResultCode.NOT_FOUND))
def test_get_vim_ticket(self): request = ServiceTicketRequest(ServiceType.VIM) response = self.host_client.get_service_ticket(request) assert_that(response.result, is_(ServiceTicketResultCode.OK))