def test_collect_all_store_softwareconfig(self): soft_config_map = { 'ec2': { 'requests_impl': test_ec2.FakeRequests }, 'cfn': { 'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self) }, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, 'request': { 'requests_impl': test_request.FakeRequests }, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, } expected_changed = set( ('heat_local', 'ec2', 'cfn', 'heat', 'local', 'request', 'dep-name1', 'dep-name2', 'dep-name3', 'zaqar')) self._test_collect_all_store(collector_kwargs_map=soft_config_map, expected_changed=expected_changed)
def _call_main(self, fake_args): # make sure we don't run forever! if '--one-time' not in fake_args: fake_args.append('--one-time') collector_kwargs_map = { 'ec2': { 'requests_impl': test_ec2.FakeRequests }, 'cfn': { 'requests_impl': test_cfn.FakeRequests(self) }, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, 'request': { 'requests_impl': test_request.FakeRequests }, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, } with mock.patch.object(config_drive, 'get_metadata') as gm: gm.return_value = {} return collect.__main__(args=fake_args, collector_kwargs_map=collector_kwargs_map)
def _call_collect_all(self, store, collector_kwargs_map=None, collectors=None): if collector_kwargs_map is None: collector_kwargs_map = { 'ec2': { 'requests_impl': test_ec2.FakeRequests }, 'cfn': { 'requests_impl': test_cfn.FakeRequests(self) }, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, 'request': { 'requests_impl': test_request.FakeRequests }, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, } if collectors is None: collectors = cfg.CONF.collectors with mock.patch.object(config_drive, 'get_metadata') as gm: gm.return_value = {} return collect.collect_all( collectors, store=store, collector_kwargs_map=collector_kwargs_map)
def test_collect_all_no_change_softwareconfig(self): soft_config_map = { 'ec2': {'requests_impl': test_ec2.FakeRequests}, 'cfn': { 'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self)}, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self) }, 'request': {'requests_impl': test_request.FakeRequests}, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self) }, } (changed_keys, paths) = self._call_collect_all( store=True, collector_kwargs_map=soft_config_map) expected_changed = set(cfg.CONF.collectors) expected_changed.add('dep-name1') expected_changed.add('dep-name2') expected_changed.add('dep-name3') self.assertEqual(expected_changed, changed_keys) # Commit for changed in changed_keys: cache.commit(changed) (changed_keys, paths2) = self._call_collect_all( store=True, collector_kwargs_map=soft_config_map) self.assertEqual(set(), changed_keys) self.assertEqual(paths, paths2)
def test_collect_all_no_change_softwareconfig(self): soft_config_map = { 'ec2': { 'requests_impl': test_ec2.FakeRequests }, 'gcore': { 'client': test_gcore.GcoreTestHeatResourceClient.from_conf() }, 'cfn': { 'requests_impl': test_cfn.FakeRequestsSoftwareConfig(self) }, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, 'request': { 'requests_impl': test_request.FakeRequests }, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self), 'discover_class': test_heat.FakeKeystoneDiscover }, } (changed_keys, paths) = self._call_collect_all(store=True, collector_kwargs_map=soft_config_map) expected_changed = set(cfg.CONF.collectors) expected_changed.add('dep-name1') expected_changed.add('dep-name2') expected_changed.add('dep-name3') self.assertEqual(expected_changed, changed_keys) # Commit for changed in changed_keys: cache.commit(changed) # Replace the ec2 requests with a failing one to simulate a transient # network failure soft_config_map['ec2'] = {'requests_impl': test_ec2.FakeFailRequests} (changed_keys, paths2) = self._call_collect_all(store=True, collector_kwargs_map=soft_config_map) self.assertEqual(set(), changed_keys) # check the second collect includes cached ec2 data despite network # failure self.assertEqual(paths, paths2)
def _call_main(self, fake_args): # make sure we don't run forever! if '--one-time' not in fake_args: fake_args.append('--one-time') collector_kwargs_map = { 'ec2': {'requests_impl': test_ec2.FakeRequests}, 'cfn': {'requests_impl': test_cfn.FakeRequests(self)}, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self) }, 'request': {'requests_impl': test_request.FakeRequests}, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self) }, } return collect.__main__(args=fake_args, collector_kwargs_map=collector_kwargs_map)
def _call_collect_all(self, mock_url_for, mock___init__, store, collector_kwargs_map=None, collectors=None): mock___init__.return_value = None mock_url_for.return_value = cfg.CONF.heat.auth_url if collector_kwargs_map is None: collector_kwargs_map = { 'ec2': {'requests_impl': test_ec2.FakeRequests}, 'cfn': {'requests_impl': test_cfn.FakeRequests(self)}, 'heat': { 'keystoneclient': test_heat.FakeKeystoneClient(self), 'heatclient': test_heat.FakeHeatClient(self) }, 'request': {'requests_impl': test_request.FakeRequests}, 'zaqar': { 'keystoneclient': test_zaqar.FakeKeystoneClient(self), 'zaqarclient': test_zaqar.FakeZaqarClient(self) }, } if collectors is None: collectors = cfg.CONF.collectors return collect.collect_all( collectors, store=store, collector_kwargs_map=collector_kwargs_map)