Exemplo n.º 1
0
 def test_remote_hostname_with_username(self, virt):
     config = Config('test', 'libvirt', server='server', username='******')
     virt.return_value.getCapabilities.return_value = LIBVIRT_CAPABILITIES_XML
     virt.return_value.getType.return_value = "LIBVIRT_TYPE"
     virt.return_value.getVersion.return_value = "VERSION 1337"
     self.run_virt(config)
     virt.assert_called_with('qemu+ssh://user@server/system?no_tty=1')
Exemplo n.º 2
0
    def test_sending_guests(self, parseFile, fromOptions, fromConfig,
                            getLogger):
        self.setUpParseFile(parseFile)
        options = Mock()
        options.oneshot = True
        options.interval = 0
        options.print_ = False
        fake_virt = Mock()
        fake_virt.CONFIG_TYPE = 'esx'
        test_hypervisor = Hypervisor('test',
                                     guestIds=[Guest('guest1', fake_virt, 1)])
        association = {'hypervisors': [test_hypervisor]}
        options.log_dir = ''
        options.log_file = ''
        getLogger.return_value = sentinel.logger
        fromConfig.return_value.config.name = 'test'
        virtwho = Executor(self.logger, options, config_dir="/nonexistant")
        config = Config("test",
                        "esx",
                        server="localhost",
                        username="******",
                        password="******",
                        owner="owner",
                        env="env")
        virtwho.configManager.addConfig(config)
        virtwho.queue = Queue()
        virtwho.queue.put(HostGuestAssociationReport(config, association))
        virtwho.run()

        fromConfig.assert_called_with(sentinel.logger, config)
        self.assertTrue(fromConfig.return_value.start.called)
        fromOptions.assert_called_with(self.logger, options, ANY)
Exemplo n.º 3
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        server.return_value.registration.new_system_user_pass.return_value = {
            'system_id': '123'
        }

        config = Config('test', 'libvirt', sat_server='localhost')
        manager = Manager.fromOptions(self.logger, options, config)
        options.env = "ENV"
        options.owner = "OWNER"
        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", {}]
        ])
Exemplo n.º 4
0
 def test_read(self, virt):
     config = Config('test', 'libvirt')
     virt.return_value.getCapabilities.return_value = LIBVIRT_CAPABILITIES_XML
     virt.return_value.getType.return_value = "LIBVIRT_TYPE"
     virt.return_value.getVersion.return_value = "VERSION 1337"
     self.run_virt(config)
     virt.assert_called_with("")
Exemplo n.º 5
0
 def test_remote_url(self, virt):
     config = Config('test', 'libvirt', server='abc://server/test')
     virt.return_value.getCapabilities.return_value = LIBVIRT_CAPABILITIES_XML
     virt.return_value.getType.return_value = "LIBVIRT_TYPE"
     virt.return_value.getVersion.return_value = "VERSION 1337"
     self.run_virt(config)
     virt.assert_called_with('abc://server/test?no_tty=1')
Exemplo n.º 6
0
 def test_sm_config_cmd(self):
     os.environ = {}
     sys.argv = ["virt-who", "--sam", "--libvirt"]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, SubscriptionManager))
Exemplo n.º 7
0
 def test_sendVirtGuests(self, rhsmconnection):
     config = Config('test', 'libvirt')
     report = DomainListReport(config, self.guestList, self.hypervisor_id)
     self.sm.sendVirtGuests(report)
     self.sm.connection.updateConsumer.assert_called_with(
         123,
         guest_uuids=[g.toDict() for g in self.guestList],
         hypervisor_id=self.hypervisor_id)
Exemplo n.º 8
0
 def test_wrong_password(self):
     options = Options("http://localhost:%s" % TEST_PORT, "username",
                       "wrong")
     options.force_register = True
     s = Satellite(self.logger, options)
     config = Config('test', 'libvirt')
     report = HostGuestAssociationReport(config, self.mapping)
     self.assertRaises(SatelliteError, s.hypervisorCheckIn, report, options)
Exemplo n.º 9
0
    def test_new_system(self):
        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.force_register = True
        s = Satellite(self.logger, options)

        config = Config('test', 'libvirt')
        report = HostGuestAssociationReport(config, self.mapping)
        s.hypervisorCheckIn(report, options)
Exemplo n.º 10
0
 def setUp(self):
     config = Config('test',
                     'esx',
                     server='localhost',
                     username='******',
                     password='******',
                     owner='owner',
                     env='env')
     self.esx = Esx(self.logger, config, None)  #  No dest given here
Exemplo n.º 11
0
    def setUp(self):
        config = Config('test', 'vdsm')

        def fakeSecureConnect(self):
            return MagicMock()

        Vdsm._secureConnect = fakeSecureConnect
        self.vdsm = Vdsm(self.logger, config)
        self.vdsm.prepare()
Exemplo n.º 12
0
 def setUp(self):
     config = Config('test',
                     'rhevm',
                     server='localhost',
                     username='******',
                     password='******',
                     owner='owner',
                     env='env')
     self.rhevm = RhevM(self.logger, config)
Exemplo n.º 13
0
 def setUp(self):
     config = Config('test',
                     'hyperv',
                     server='localhost',
                     username='******',
                     password='******',
                     owner='owner',
                     env='env')
     self.hyperv = HyperV(self.logger, config)
Exemplo n.º 14
0
 def setUp(self):
     config = Config('test',
                     'xen',
                     server='localhost',
                     username='******',
                     password='******',
                     owner='owner',
                     env='env')
     self.xen = Xen(self.logger, config)
Exemplo n.º 15
0
 def test_sendVirtGuests(self, create_from_file, connection):
     self.prepare(create_from_file, connection)
     config = Config('test', 'libvirt')
     config.smType = 'sam'
     manager = Manager.fromOptions(self.logger, self.options, 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)
Exemplo n.º 16
0
 def test_mapping_has_no_hostname_when_unavailible(self, virt):
     config = Config('test', 'libvirt', server='abc://server/test')
     datastore = Datastore()
     virt.return_value.getCapabilities.return_value = LIBVIRT_CAPABILITIES_NO_HOSTNAME_XML
     virt.return_value.getType.return_value = "LIBVIRT_TYPE"
     virt.return_value.getVersion.return_value = "VERSION 1337"
     self.run_virt(config, datastore)
     result = datastore.get(config.name)
     for host in result.association['hypervisors']:
         self.assertTrue(host.name is None)
Exemplo n.º 17
0
    def test_duplicate_reports_are_ignored(self):
        """
        Test that duplicate reports are filtered out when retrieving items
        from the data store
        """
        source_keys = ['source1', 'source2']
        interval = 1
        terminate_event = Mock()
        options = Mock()
        options.print_ = False
        config1 = Config('source1', 'esx')
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'
        config = Mock()
        manager = Mock()

        guest1 = Guest('GUUID1', virt1, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')
        report2 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_2')
        report3 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_3')
        datastore = {
            'source1': report1,  # Not changing, should be excluded later
            'source2': report2,  # Will change the report sent for source2
        }
        data_to_send = {
            'source1': report1,
            'source2': report2,
        }
        logger = Mock()
        destination_thread = DestinationThread(logger,
                                               config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=False,
                                               options=options)
        destination_thread._send_data(data_to_send=data_to_send)

        expected_hashes = {}
        for source_key, report in data_to_send.iteritems():
            expected_hashes[source_key] = report.hash

        self.assertEqual(destination_thread.last_report_for_source,
                         expected_hashes)
        # Pretend there were updates to the datastore from elsewhere
        destination_thread.source['source2'] = report3

        next_data_to_send = destination_thread._get_data()
        expected_next_data_to_send = {'source2': report3}
        self.assertEqual(next_data_to_send, expected_next_data_to_send)
Exemplo n.º 18
0
 def test_remote_url_with_username_and_password(self, virt):
     config = Config('test',
                     'libvirt',
                     server='abc://server/test',
                     username='******',
                     password='******')
     virt.return_value.getCapabilities.return_value = LIBVIRT_CAPABILITIES_XML
     virt.return_value.getType.return_value = "LIBVIRT_TYPE"
     virt.return_value.getVersion.return_value = "VERSION 1337"
     self.run_virt(config)
     virt.assert_called_with('abc://user@server/test?no_tty=1', ANY, ANY)
Exemplo n.º 19
0
    def setUpClass(cls, rhsmcert, rhsmconfig):
        super(TestSubscriptionManager, cls).setUpClass()
        config = Config('test', 'libvirt')
        cls.tempdir = tempfile.mkdtemp()
        with open(os.path.join(cls.tempdir, 'cert.pem'), 'w') as f:
            f.write("\n")

        rhsmcert.return_value.subject = {'CN': 123}
        rhsmconfig.return_value.get.side_effect = lambda group, key: {'consumerCertDir': cls.tempdir}.get(key, DEFAULT)
        cls.sm = SubscriptionManager(cls.logger, config)
        cls.sm.cert_uuid = 123
Exemplo n.º 20
0
 def test_sm_config_env(self):
     os.environ = {
         "VIRTWHO_SAM": '1',
         "VIRTWHO_LIBVIRT": '1'
     }
     sys.argv = ["virt-who"]
     logger, options = parseOptions()
     config = Config("env/cmdline", options.virtType, defaults={}, **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, SubscriptionManager))
Exemplo n.º 21
0
 def mock_virtwho(self):
     options = Mock()
     options.interval = 6
     options.oneshot = False
     options.print_ = False
     virtwho = Executor(Mock(), options, config_dir="/nonexistant")
     config = Config("env/cmdline", 'libvirt')
     virtwho.configManager.addConfig(config)
     virtwho.queue = Mock()
     virtwho.send = Mock()
     return virtwho
Exemplo n.º 22
0
    def test_hypervisorCheckIn(self):
        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.force_register = True
        s = Satellite(self.logger, options)

        config = Config('test', 'libvirt')
        report = HostGuestAssociationReport(config, self.mapping)
        result = s.hypervisorCheckIn(report, options)
        self.assertTrue("failedUpdate" in result)
        self.assertTrue("created" in result)
        self.assertTrue("updated" in result)
Exemplo n.º 23
0
    def test_creating_channel(self):
        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.force_register = True
        s = Satellite(self.logger, options)

        config = Config('test', 'libvirt')
        report = HostGuestAssociationReport(config, self.mapping)
        result = s.hypervisorCheckIn(report, options)
        self.assertTrue(self.fake_server.channel_created)
        self.assertIsNotNone(self.fake_server.created_system)
        self.assertTrue("created" in result)
Exemplo n.º 24
0
    def test_hypervisorCheckIn(self, rhsmconnection):
        owner = "owner"
        env = "env"
        config = Config("test", "esx", owner=owner, env=env)
        # Ensure the data takes the proper for for the old API
        rhsmconnection.return_value.has_capability.return_value = False
        report = HostGuestAssociationReport(config, self.mapping)
        self.sm.hypervisorCheckIn(report)

        self.sm.connection.hypervisorCheckIn.assert_called_with(
            owner,
            env,
            dict((host.hypervisorId, [g.toDict() for g in host.guestIds]) for host in self.mapping['hypervisors']), options=None)
Exemplo n.º 25
0
    def test_per_config_options(self):
        options = Options(None, None, None)
        options.force_register = True
        config = Config('test',
                        'libvirt',
                        sat_server="http://localhost:%s" % TEST_PORT,
                        sat_username='******',
                        sat_password='******')
        s = Satellite(self.logger, options)

        report = HostGuestAssociationReport(config, self.mapping)
        result = s.hypervisorCheckIn(report, options)
        self.assertTrue("failedUpdate" in result)
        self.assertTrue("created" in result)
        self.assertTrue("updated" in result)
Exemplo n.º 26
0
class TestManager(TestBase):
    """ Test of all available subscription managers. """
    guest1 = Guest('9c927368-e888-43b4-9cdb-91b10431b258', xvirt, Guest.STATE_RUNNING)
    guest2 = Guest('d5ffceb5-f79d-41be-a4c1-204f836e144a', xvirt, Guest.STATE_SHUTOFF)
    guestInfo = [guest1]
    hypervisor_id = "HYPERVISOR_ID"

    config = Config('test', 'libvirt', owner='OWNER', env='ENV')
    host_guest_report = HostGuestAssociationReport(config, {
        'hypervisors': [
            Hypervisor('9c927368-e888-43b4-9cdb-91b10431b258', []),
            Hypervisor('ad58b739-5288-4cbc-a984-bd771612d670', [guest1, guest2])
        ]
    })
    domain_report = DomainListReport(config, [guest1], hypervisor_id)
Exemplo n.º 27
0
 def test_hypervisorCheckInAsync(self, rhsmconnection):
     owner = 'owner'
     env = 'env'
     config = Config("test", "esx", owner=owner, env=env)
     # Ensure we try out the new API
     rhsmconnection.return_value.has_capability.return_value = True
     report = HostGuestAssociationReport(config, self.mapping)
     self.sm.hypervisorCheckIn(report)
     expected = {'hypervisors': [h.toDict() for h in self.mapping['hypervisors']]}
     self.sm.connection.hypervisorCheckIn.assert_called_with(
         owner,
         env,
         expected,
         options=None
     )
Exemplo n.º 28
0
 def test_satellite_config_cmd(self):
     os.environ = {}
     sys.argv = [
         "virt-who", "--satellite", "--satellite-server=sat.example.com",
         "--satellite-username=username", "--satellite-password=password",
         "--libvirt"
     ]
     logger, options = parseOptions()
     config = Config("env/cmdline",
                     options.virtType,
                     defaults={},
                     **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, Satellite))
Exemplo n.º 29
0
 def test_satellite_config_env(self):
     os.environ = {
         "VIRTWHO_SATELLITE": '1',
         "VIRTWHO_SATELLITE_SERVER": 'sat.example.com',
         "VIRTWHO_SATELLITE_USERNAME": '******',
         "VIRTWHO_SATELLITE_PASSWORD": '******',
         "VIRTWHO_LIBVIRT": '1'
     }
     sys.argv = ["virt-who"]
     logger, options = parseOptions()
     config = Config("env/cmdline",
                     options.virtType,
                     defaults={},
                     **options)
     config.checkOptions(logger)
     manager = Manager.fromOptions(logger, options, config)
     self.assertTrue(isinstance(manager, Satellite))
Exemplo n.º 30
0
    def test_send_data_429_during_send_virt_guests(self):
        # Show that when a 429 is encountered during the sending of a
        # DomainListReport that we retry after waiting the appropriate
        # amount of time
        source_keys = ['source1']
        config1 = Config('source1', 'esx')
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')

        datastore = {'source1': report1}
        data_to_send = {'source1': report1}

        config = Mock()
        config.polling_interval = 10
        logger = Mock()

        error_to_throw = ManagerThrottleError(retry_after=21)

        manager = Mock()
        manager.sendVirtGuests = Mock(side_effect=[error_to_throw, report1])
        terminate_event = Mock()
        interval = 10
        options = Mock()
        options.print_ = False
        destination_thread = DestinationThread(logger,
                                               config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=True,
                                               options=options)
        destination_thread.wait = Mock()
        destination_thread._send_data(data_to_send)
        manager.sendVirtGuests.assert_has_calls([
            call(report1, options=destination_thread.options),
            call(report1, options=destination_thread.options)
        ])
        destination_thread.wait.assert_has_calls(
            [call(wait_time=error_to_throw.retry_after)])