Ejemplo n.º 1
0
    def test_sending_guests(self, fromOptions, fromConfig, getLogger):
        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 = VirtWho(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)
Ejemplo n.º 2
0
 def setUp(self):
     self.config = Config('config',
                          'esx',
                          server='localhost',
                          username='******',
                          password='******',
                          owner='owner',
                          env='env',
                          log_dir='',
                          log_file='')
     self.second_config = Config('second_config',
                                 'esx',
                                 server='localhost',
                                 username='******',
                                 password='******',
                                 owner='owner',
                                 env='env',
                                 log_dir='',
                                 log_file='')
     fake_virt = Mock()
     fake_virt.CONFIG_TYPE = 'esx'
     guests = [Guest('guest1', fake_virt, 1)]
     test_hypervisor = Hypervisor('test',
                                  guestIds=[Guest('guest1', fake_virt, 1)])
     assoc = {'hypervisors': [test_hypervisor]}
     self.fake_domain_list = DomainListReport(self.second_config, guests)
     self.fake_report = HostGuestAssociationReport(self.config, assoc)
Ejemplo n.º 3
0
 def test_oneshot(self, mock_client):
     expected_assoc = '"well formed HostGuestMapping"'
     expected_report = HostGuestAssociationReport(self.esx.config,
                                                  expected_assoc)
     updateSet = Mock()
     updateSet.version = 'some_new_version_string'
     updateSet.truncated = False
     mock_client.return_value.service.WaitForUpdatesEx.return_value = updateSet
     queue = Queue()
     self.esx.applyUpdates = Mock()
     getHostGuestMappingMock = Mock()
     getHostGuestMappingMock.return_value = expected_assoc
     self.esx.getHostGuestMapping = getHostGuestMappingMock
     self.run_once(queue)
     self.assertEqual(queue.qsize(), 1)
     result_report = queue.get(block=True, timeout=1)
     self.assertEqual(expected_report.config.hash,
                      result_report.config.hash)
     self.assertEqual(expected_report._assoc, result_report._assoc)