def __init__(self, osc=None): """:param osc: an OpenStackClients instance""" self.osc = osc if osc else clients.OpenStackClients() self.ceilometer = self.osc.ceilometer() LOG.warning("Ceilometer API is deprecated and Ceilometer Datasource " "module is no longer maintained. We recommend to use " "Gnocchi instead.")
def __init__(self, osc=None): """:param osc: an OpenStackClients instance""" self.osc = osc if osc else clients.OpenStackClients() self.neutron = self.osc.neutron() self.cinder = self.osc.cinder() self.nova = self.osc.nova() self.glance = self.osc.glance()
def test_clients_gnocchi_diff_vers(self, mock_session): # gnocchiclient currently only has one version (v1) CONF.set_override('api_version', '1', group='gnocchi_client') osc = clients.OpenStackClients() osc._gnocchi = None osc.gnocchi() self.assertEqual(gnclient_v1.Client, type(osc.gnocchi()))
def test_clients_ironic(self, mock_session, mock_call): ironic_url = 'http://localhost:6385/' mock_session.get_endpoint.return_value = ironic_url osc = clients.OpenStackClients() osc._ironic = None osc.ironic() mock_call.assert_called()
def test_clients_neutron_diff_vers(self, mock_session): '''neutronclient currently only has one version (v2)''' CONF.set_override('api_version', '2.0', group='neutron_client') osc = clients.OpenStackClients() osc._neutron = None osc.neutron() self.assertEqual(netclient_v2.Client, type(osc.neutron()))
def test_clients_gnocchi_diff_endpoint(self, mock_session): # gnocchiclient currently only has one version (v1) CONF.set_override('endpoint_type', 'publicURL', group='gnocchi_client') osc = clients.OpenStackClients() osc._gnocchi = None osc.gnocchi() self.assertEqual('publicURL', osc.gnocchi().api.interface)
def test_clients_glance_diff_endpoint(self, mock_session): CONF.set_override('endpoint_type', 'internalURL', group='glance_client') osc = clients.OpenStackClients() osc._glance = None osc.glance() self.assertEqual('internalURL', osc.glance().http_client.interface)
def test_clients_cinder_diff_endpoint(self, mock_session): CONF.set_override('endpoint_type', 'internalURL', group='cinder_client') osc = clients.OpenStackClients() osc._cinder = None osc.cinder() self.assertEqual('internalURL', osc.cinder().client.interface)
def test_clients_nova_bad_min_version(self, mock_session): CONF.set_override('api_version', '2.47', group='nova_client') osc = clients.OpenStackClients() osc._nova = None ex = self.assertRaises(ValueError, osc.nova) self.assertIn('Invalid nova_client.api_version 2.47', six.text_type(ex))
def do_execute_strategy(self, audit, request_context): osc = clients.OpenStackClients() # todo(jed) retrieve in audit parameters (threshold,...) # todo(jed) create ActionPlan goal = objects.Goal.get_by_id(request_context, audit.goal_id) # NOTE(jed56) In the audit object, the 'strategy_id' attribute # is optional. If the admin wants to force the trigger of a Strategy # it could specify the Strategy uuid in the Audit. strategy_name = None if audit.strategy_id: strategy = objects.Strategy.get_by_id(request_context, audit.strategy_id) strategy_name = strategy.name strategy_selector = default.DefaultStrategySelector( goal_name=goal.name, strategy_name=strategy_name, osc=osc) selected_strategy = strategy_selector.select() selected_strategy.audit_scope = audit.scope schema = selected_strategy.get_schema() if not audit.parameters and schema: # Default value feedback if no predefined strategy utils.StrictDefaultValidatingDraft4Validator(schema).validate( audit.parameters) selected_strategy.input_parameters.update( {name: value for name, value in audit.parameters.items()}) return selected_strategy.execute()
def __init__(self, config, osc=None): super(BaseClusterDataModelCollector, self).__init__(config) self.osc = osc if osc else clients.OpenStackClients() self._cluster_data_model = None self.lock = threading.RLock() self._audit_scope_handler = None self._data_model_scope = None
def test_clients_ceilometer(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._ceilometer = None osc.ceilometer() mock_call.assert_called_once_with(CONF.ceilometer_client.api_version, None, session=mock_session)
def test_clients_neutron_diff_endpoint(self, mock_session): '''neutronclient currently only has one version (v2)''' CONF.set_override('endpoint_type', 'publicURL', group='neutron_client') osc = clients.OpenStackClients() osc._neutron = None osc.neutron() self.assertEqual('publicURL', osc.neutron().httpclient.interface)
def test_clients_glance(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._glance = None osc.glance() mock_call.assert_called_once_with( CONF.glance_client.api_version, interface=CONF.glance_client.endpoint_type, session=mock_session)
def test_clients_ironic_cached(self, mock_session): ironic_url = 'http://localhost:6385/' mock_session.get_endpoint.return_value = ironic_url osc = clients.OpenStackClients() osc._ironic = None ironic = osc.ironic() ironic_cached = osc.ironic() self.assertEqual(ironic, ironic_cached)
def test_clients_neutron(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._neutron = None osc.neutron() mock_call.assert_called_once_with( CONF.neutron_client.api_version, endpoint_type=CONF.neutron_client.endpoint_type, session=mock_session)
def test_clients_ironic_diff_vers(self, mock_session): ironic_url = 'http://localhost:6385/' mock_session.get_endpoint.return_value = ironic_url CONF.set_override('api_version', '1', group='ironic_client') osc = clients.OpenStackClients() osc._ironic = None osc.ironic() self.assertEqual(irclient_v1.Client, type(osc.ironic()))
def test_clients_gnocchi(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._gnocchi = None osc.gnocchi() mock_call.assert_called_once_with( CONF.gnocchi_client.api_version, adapter_options={"interface": CONF.gnocchi_client.endpoint_type}, session=mock_session)
def test_clients_ceilometer_cached(self, mock_get_redirect_client, mock_session): mock_get_redirect_client.return_value = [mock.Mock(), mock.Mock()] osc = clients.OpenStackClients() osc._ceilometer = None ceilometer = osc.ceilometer() ceilometer_cached = osc.ceilometer() self.assertEqual(ceilometer, ceilometer_cached)
def test_clients_cinder(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._cinder = None osc.cinder() mock_call.assert_called_once_with( CONF.cinder_client.api_version, endpoint_type=CONF.cinder_client.endpoint_type, session=mock_session)
def setUp(self): super(TestIronicHelper, self).setUp() osc = clients.OpenStackClients() p_ironic = mock.patch.object(osc, 'ironic') p_ironic.start() self.addCleanup(p_ironic.stop) self.ironic_util = ironic_helper.IronicHelper(osc=osc)
def test_get_keystone_session(self): _AUTH_CONF_GROUP = 'watcher_clients_auth' ka_loading.register_auth_conf_options(cfg.CONF, _AUTH_CONF_GROUP) ka_loading.register_session_conf_options(cfg.CONF, _AUTH_CONF_GROUP) cfg.CONF.set_override('auth_type', 'password', group=_AUTH_CONF_GROUP) # If we don't clean up the _AUTH_CONF_GROUP conf options, then other # tests that run after this one will fail, complaining about required # options that _AUTH_CONF_GROUP wants. def cleanup_conf_from_loading(): # oslo_config doesn't seem to allow unregistering groups through a # single method, so we do this instead cfg.CONF.reset() del cfg.CONF._groups[_AUTH_CONF_GROUP] self.addCleanup(cleanup_conf_from_loading) osc = clients.OpenStackClients() expected = { 'username': '******', 'password': '******', 'auth_url': 'http://server.ip:35357', 'user_domain_id': 'foouserdomainid', 'project_domain_id': 'fooprojdomainid' } def reset_register_opts_mock(conf_obj, original_method): conf_obj.register_opts = original_method original_register_opts = cfg.CONF.register_opts self.addCleanup(reset_register_opts_mock, cfg.CONF, original_register_opts) # Because some of the conf options for auth plugins are not registered # until right before they are loaded, and because the method that does # the actual loading of the conf option values is an anonymous method # (see _getter method of load_from_conf_options in # keystoneauth1.loading.conf.py), we need to manually monkey patch # the register opts method so that we can override the conf values to # our custom values. def mock_register_opts(*args, **kwargs): ret = original_register_opts(*args, **kwargs) if 'group' in kwargs and kwargs['group'] == _AUTH_CONF_GROUP: for key, value in expected.items(): cfg.CONF.set_override(key, value, group=_AUTH_CONF_GROUP) return ret cfg.CONF.register_opts = mock_register_opts sess = osc.session self.assertEqual(expected['auth_url'], sess.auth.auth_url) self.assertEqual(expected['username'], sess.auth._username) self.assertEqual(expected['password'], sess.auth._password) self.assertEqual(expected['user_domain_id'], sess.auth._user_domain_id) self.assertEqual(expected['project_domain_id'], sess.auth._project_domain_id)
def test_clients_ceilometer_diff_endpoint(self, mock_get_redirect_client, mock_session): mock_get_redirect_client.return_value = [mock.Mock(), mock.Mock()] CONF.set_override('endpoint_type', 'publicURL', group='ceilometer_client') osc = clients.OpenStackClients() osc._ceilometer = None osc.ceilometer() self.assertEqual('publicURL', osc.ceilometer().http_client.interface)
def test_clients_ceilometer_diff_vers(self, mock_get_redirect_client, mock_session): '''ceilometerclient currently only has one version (v2)''' mock_get_redirect_client.return_value = [mock.Mock(), mock.Mock()] CONF.set_override('api_version', '2', group='ceilometer_client') osc = clients.OpenStackClients() osc._ceilometer = None osc.ceilometer() self.assertEqual(ceclient_v2.Client, type(osc.ceilometer()))
def test_clients_nova(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._nova = None osc.nova() mock_call.assert_called_once_with( CONF.nova_client.api_version, endpoint_type=CONF.nova_client.endpoint_type, region_name=CONF.nova_client.region_name, session=mock_session)
def test_clients_ironic(self, mock_session, mock_call): osc = clients.OpenStackClients() osc._ironic = None osc.ironic() mock_call.assert_called_once_with(CONF.ironic_client.api_version, CONF.ironic_client.endpoint_type, max_retries=None, os_ironic_api_version=None, retry_interval=None, session=mock_session)
def test_clients_placement(self, mock_session, mock_call): osc = clients.OpenStackClients() osc.placement() headers = {'accept': 'application/json'} mock_call.assert_called_once_with( session=mock_session, service_type='placement', default_microversion=CONF.placement_client.api_version, interface=CONF.placement_client.interface, region_name=CONF.placement_client.region_name, additional_headers=headers)
def test_clients_ironic(self, mock_session, mock_call): ironic_url = 'http://localhost:6385/' mock_session.get_endpoint.return_value = ironic_url osc = clients.OpenStackClients() osc._ironic = None osc.ironic() mock_call.assert_called_once_with(CONF.ironic_client.api_version, ironic_url, max_retries=None, os_ironic_api_version=None, retry_interval=None, session=mock_session)
def test_clients_monasca_diff_vers(self, mock_session): mock_session.return_value = mock.Mock( get_endpoint=mock.Mock(return_value='test_endpoint'), get_token=mock.Mock(return_value='test_token'),) self._register_watcher_clients_auth_opts() CONF.set_override('api_version', '2_0', group='monasca_client') osc = clients.OpenStackClients() osc._monasca = None osc.monasca() self.assertEqual(monclient_v2.Client, type(osc.monasca()))
def test_clients_monasca_cached(self, mock_session): mock_session.return_value = mock.Mock( get_endpoint=mock.Mock(return_value='test_endpoint'), get_token=mock.Mock(return_value='test_token'),) self._register_watcher_clients_auth_opts() osc = clients.OpenStackClients() osc._monasca = None monasca = osc.monasca() monasca_cached = osc.monasca() self.assertEqual(monasca, monasca_cached)