Example #1
0
    def test_report_hash_added_after_send(self, fromConfig, fromOptions, getLogger):
        # Side effect for fromConfig
        def fake_virts(logger, config):
            new_fake_virt = Mock()
            new_fake_virt.config.name = config.name
            return new_fake_virt

        fromConfig.side_effect = fake_virts
        options = Mock()
        options.interval = 0
        options.oneshot = True
        options.print_ = False
        options.log_file = ''
        options.log_dir = ''
        virtwho = Executor(self.logger, options, config_dir="/nonexistant")

        def send(report):
            report.state = AbstractVirtReport.STATE_FINISHED
            return True
        virtwho.send = Mock(side_effect=send)
        queue = Queue()
        virtwho.queue = queue
        virtwho.retry_after = 1
        virtwho.configManager.addConfig(self.config)
        virtwho.configManager.addConfig(self.second_config)
        queue.put(self.fake_report)
        queue.put(self.fake_domain_list)
        virtwho.run()

        self.assertEquals(virtwho.send.call_count, 2)
        self.assertEqual(virtwho.last_reports_hash[self.config.name], self.fake_report.hash)
        self.assertEqual(virtwho.last_reports_hash[self.second_config.name], self.fake_domain_list.hash)
Example #2
0
    def test_same_report_filtering(self, fromConfig, fromOptions, getLogger):
        def fake_virts(logger, config):
            new_fake_virt = Mock()
            new_fake_virt.config.name = config.name
            return new_fake_virt

        fromConfig.side_effect = fake_virts
        options = Mock()
        options.interval = 0
        options.oneshot = True
        options.print_ = False
        options.log_dir = ''
        options.log_file = ''
        virtwho = Executor(self.logger, options, config_dir="/nonexistant")

        queue = Queue()
        # Create another report with same hash
        report2 = HostGuestAssociationReport(self.config, self.fake_report.association)
        self.assertEqual(self.fake_report.hash, report2.hash)

        def send(report):
            report.state = AbstractVirtReport.STATE_FINISHED
            # Put second report when the first is done
            queue.put(report2)
            return True
        virtwho.send = Mock(side_effect=send)
        virtwho.queue = queue
        virtwho.retry_after = 1
        virtwho.configManager.addConfig(self.config)
        queue.put(self.fake_report)
        virtwho.run()

        self.assertEquals(virtwho.send.call_count, 1)
Example #3
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)
Example #4
0
    def test_same_report_filtering(self, fromConfig, fromOptions, getLogger):
        def fake_virts(logger, config):
            new_fake_virt = Mock()
            new_fake_virt.config.name = config.name
            return new_fake_virt

        fromConfig.side_effect = fake_virts
        options = Mock()
        options.interval = 0
        options.oneshot = True
        options.print_ = False
        options.log_dir = ''
        options.log_file = ''
        virtwho = Executor(self.logger, options, config_dir="/nonexistant")

        queue = Queue()
        # Create another report with same hash
        report2 = HostGuestAssociationReport(self.config,
                                             self.fake_report.association)
        self.assertEqual(self.fake_report.hash, report2.hash)

        def send(report):
            report.state = AbstractVirtReport.STATE_FINISHED
            # Put second report when the first is done
            queue.put(report2)
            return True

        virtwho.send = Mock(side_effect=send)
        virtwho.queue = queue
        virtwho.retry_after = 1
        virtwho.configManager.addConfig(self.config)
        queue.put(self.fake_report)
        virtwho.run()

        self.assertEquals(virtwho.send.call_count, 1)
Example #5
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)
Example #6
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
Example #7
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
Example #8
0
    def test_report_hash_added_after_send(self, fromConfig, fromOptions,
                                          getLogger):
        # Side effect for fromConfig
        def fake_virts(logger, config):
            new_fake_virt = Mock()
            new_fake_virt.config.name = config.name
            return new_fake_virt

        fromConfig.side_effect = fake_virts
        options = Mock()
        options.interval = 0
        options.oneshot = True
        options.print_ = False
        options.log_file = ''
        options.log_dir = ''
        virtwho = Executor(self.logger, options, config_dir="/nonexistant")

        def send(report):
            report.state = AbstractVirtReport.STATE_FINISHED
            return True

        virtwho.send = Mock(side_effect=send)
        queue = Queue()
        virtwho.queue = queue
        virtwho.retry_after = 1
        virtwho.configManager.addConfig(self.config)
        virtwho.configManager.addConfig(self.second_config)
        queue.put(self.fake_report)
        queue.put(self.fake_domain_list)
        virtwho.run()

        self.assertEquals(virtwho.send.call_count, 2)
        self.assertEqual(virtwho.last_reports_hash[self.config.name],
                         self.fake_report.hash)
        self.assertEqual(virtwho.last_reports_hash[self.second_config.name],
                         self.fake_domain_list.hash)