def test_hypervisorCheckIn(self, server): options = MagicMock() server.return_value.registration.new_system_user_pass.return_value = { 'system_id': '123' } config, d = self.create_fake_config('test', **self.default_config_args) manager = Manager.from_config(self.logger, config) self.host_guest_report._config = config manager.hypervisorCheckIn(self.host_guest_report, options) manager.server_xmlrpc.registration.virt_notify.assert_called_with(ANY, [ [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}], [0, "crawl_began", "system", {}], [0, "exists", "domain", { "memory_size": 0, "name": "VM 9c927368-e888-43b4-9cdb-91b10431b258 from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670", "state": "running", "uuid": "9c927368e88843b49cdb91b10431b258", "vcpus": 1, "virt_type": "fully_virtualized" }], [0, "exists", "domain", { "memory_size": 0, "name": "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670", "state": "shutoff", "uuid": "d5ffceb5f79d41bea4c1204f836e144a", "vcpus": 1, "virt_type": "fully_virtualized" }], [0, "crawl_ended", "system", {}] ])
def test_sm_config_cmd(self): os.environ = {} sys.argv = ["virt-who", "--sam", "--libvirt"] logger, effective_config = parse_options() config_manager = DestinationToSourceMapper(effective_config) self.assertEqual(len(config_manager.configs), 1) config = dict(config_manager.configs)[VW_ENV_CLI_SECTION_NAME] manager = Manager.from_config(self.logger, config) self.assertTrue(isinstance(manager, SubscriptionManager))
def test_sendVirtGuests(self, create_from_file, connection): self.prepare(create_from_file, connection) config = VirtConfigSection.from_dict({'type': 'libvirt', 'sm_type': 'sam'}, 'test', None) manager = Manager.from_config(self.logger, config) manager.sendVirtGuests(self.domain_report, self.options) manager.connection.updateConsumer.assert_called_with( ANY, guest_uuids=[guest.toDict() for guest in self.guestInfo], hypervisor_id=self.hypervisor_id)
def test_sendVirtGuests(self): config = VirtConfigSection.from_dict( { 'type': 'libvirt', 'sat_server': 'localhost' }, 'test', None) manager = Manager.from_config(self.logger, config) self.assertRaises(ManagerError, manager.sendVirtGuests, self.domain_report)
def test_sm_config_env(self): os.environ = { "VIRTWHO_SAM": '1', "VIRTWHO_LIBVIRT": '1' } sys.argv = ["virt-who"] logger, config = parse_options() manager = Manager.from_config(logger, config) self.assertTrue(isinstance(manager, SubscriptionManager))
def test_sendVirtGuests(self, create_from_file, connection): self.prepare(create_from_file, connection) config, d = self.create_fake_config('test', **self.default_config_args) manager = Manager.from_config(self.logger, config) self.domain_report._config = config manager.sendVirtGuests(self.domain_report, self.options) manager.connection.updateConsumer.assert_called_with( ANY, guest_uuids=[guest.toDict() for guest in self.guestInfo], hypervisor_id=self.hypervisor_id)
def test_sendVirtGuests(self, create_from_file, connection): self.prepare(create_from_file, connection) config = VirtConfigSection.from_dict( { 'type': 'libvirt', 'sm_type': 'sam' }, 'test', None) manager = Manager.from_config(self.logger, config) manager.sendVirtGuests(self.domain_report, self.options) manager.connection.updateConsumer.assert_called_with( ANY, guest_uuids=[guest.toDict() for guest in self.guestInfo], hypervisor_id=self.hypervisor_id)
def test_hypervisorCheckIn(self, create_from_file, connection): self.prepare(create_from_file, connection) config, d = self.create_fake_config('test', **self.default_config_args) d['owner'] = 'OWNER' manager = Manager.from_config(self.logger, config) # TODO additional mocking. Specifically, mock out the host_guest_report and config... self.host_guest_report._config = config manager.hypervisorCheckIn(self.host_guest_report) manager.connection.hypervisorCheckIn.assert_called_with( d['owner'], '', dict( (host.hypervisorId, [guest.toDict() for guest in host.guestIds]) for host in self.host_guest_report.association['hypervisors']), options=ANY)
def test_sm_config_file(self): config_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, config_dir) with open(os.path.join(config_dir, "test.conf"), "w") as f: f.write(""" [test] type=libvirt owner=owner env=env rhsm_hostname=host rhsm_port=8080 rhsm_prefix=prefix rhsm_proxy_hostname=proxy_host rhsm_proxy_port=9090 rhsm_proxy_user=proxy_user rhsm_proxy_password=proxy_password rhsm_insecure=1 rhsm_username=user rhsm_password=passwd rhsm_no_proxy=filter """) config_manager = DestinationToSourceMapper( init_config({}, {}, config_dir=config_dir)) self.assertEqual(len(config_manager.configs), 1) config = dict(config_manager.configs)["test"] manager = Manager.from_config(self.logger, config) self.assertTrue(isinstance(manager, SubscriptionManager)) self.assertEqual(config['rhsm_hostname'], 'host') self.assertEqual(config['rhsm_port'], '8080') manager._connect(config) self.sm.connection.assert_called_with( username='******', password='******', host='host', ssl_port=8080, handler='prefix', proxy_hostname='proxy_host', proxy_port='9090', proxy_user='******', proxy_password='******', no_proxy='filter', insecure='1', correlation_id=manager.correlation_id)
def test_sm_config_file(self): config_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, config_dir) with open(os.path.join(config_dir, "test.conf"), "w") as f: f.write(""" [test] type=libvirt owner=owner env=env rhsm_hostname=host rhsm_port=8080 rhsm_prefix=prefix rhsm_proxy_hostname=proxy_host rhsm_proxy_port=9090 rhsm_proxy_user=proxy_user rhsm_proxy_password=proxy_password rhsm_insecure=1 rhsm_username=user rhsm_password=passwd rhsm_no_proxy=filter """) config_manager = DestinationToSourceMapper(init_config({}, {}, config_dir=config_dir)) self.assertEqual(len(config_manager.configs), 1) config = dict(config_manager.configs)["test"] manager = Manager.from_config(self.logger, config) self.assertTrue(isinstance(manager, SubscriptionManager)) self.assertEqual(config['rhsm_hostname'], 'host') self.assertEqual(config['rhsm_port'], '8080') manager._connect(config) self.sm.connection.assert_called_with( username='******', password='******', host='host', ssl_port=8080, handler='prefix', proxy_hostname='proxy_host', proxy_port='9090', proxy_user='******', proxy_password='******', no_proxy='filter', insecure='1', correlation_id=manager.correlation_id)
def test_hypervisorCheckIn(self, create_from_file, connection): self.prepare(create_from_file, connection) config, d = self.create_fake_config('test', **self.default_config_args) d['owner'] = 'OWNER' manager = Manager.from_config(self.logger, config) # TODO additional mocking. Specifically, mock out the host_guest_report and config... self.host_guest_report._config = config manager.hypervisorCheckIn(self.host_guest_report) manager.connection.hypervisorCheckIn.assert_called_with( d['owner'], '', dict( ( host.hypervisorId, [ guest.toDict() for guest in host.guestIds ] ) for host in self.host_guest_report.association['hypervisors']), options=ANY)
def test_hypervisorCheckIn(self, server): options = MagicMock() server.return_value.registration.new_system_user_pass.return_value = { 'system_id': '123' } config, d = self.create_fake_config('test', **self.default_config_args) manager = Manager.from_config(self.logger, config) self.host_guest_report._config = config manager.hypervisorCheckIn(self.host_guest_report, options) manager.server_xmlrpc.registration.virt_notify.assert_called_with( ANY, [[ 0, "exists", "system", { "identity": "host", "uuid": "0000000000000000" } ], [0, "crawl_began", "system", {}], [ 0, "exists", "domain", { "memory_size": 0, "name": "VM 9c927368-e888-43b4-9cdb-91b10431b258 from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670", "state": "running", "uuid": "9c927368e88843b49cdb91b10431b258", "vcpus": 1, "virt_type": "fully_virtualized" } ], [ 0, "exists", "domain", { "memory_size": 0, "name": "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670", "state": "shutoff", "uuid": "d5ffceb5f79d41bea4c1204f836e144a", "vcpus": 1, "virt_type": "fully_virtualized" } ], [0, "crawl_ended", "system", {}]])
def test_sm_config_env(self): os.environ = {"VIRTWHO_SAM": '1', "VIRTWHO_LIBVIRT": '1'} sys.argv = ["virt-who"] logger, config = parse_options() manager = Manager.from_config(logger, config) self.assertTrue(isinstance(manager, SubscriptionManager))
def test_sendVirtGuests(self): config = VirtConfigSection.from_dict({'type': 'libvirt', 'sat_server': 'localhost'}, 'test', None) manager = Manager.from_config(self.logger, config) self.assertRaises(ManagerError, manager.sendVirtGuests, self.domain_report)