def _test_clients_glance(self, expected_region_name, mock_keystone, mock_call): mock_session = mock_keystone.return_value.session mock_session.get_endpoint.return_value = 'glance_url' fake_region = 'fake_region' fake_endpoint = 'fake_endpoint' zun.conf.CONF.set_override('region_name', fake_region, group='glance_client') zun.conf.CONF.set_override('endpoint_type', fake_endpoint, group='glance_client') con = mock.MagicMock() obj = clients.OpenStackClients(con) obj._glance = None obj.glance() mock_session.get_endpoint.assert_called_once_with( region_name=fake_region, service_type='image', interface=fake_endpoint) mock_call.assert_called_once_with( zun.conf.CONF.glance_client.api_version, endpoint='glance_url', session=mock_session)
def test_url_for(self, mock_keystone): obj = clients.OpenStackClients(None) obj.url_for(service_type='fake_service', interface='fake_endpoint') mock_endpoint = mock_keystone.return_value.session.get_endpoint mock_endpoint.assert_called_once_with(service_type='fake_service', interface='fake_endpoint')
def __init__(self, context): self.context = context self.client = clients.OpenStackClients(self.context).neutron() self.admin_client = None self.pci_whitelist = pci_whitelist.Whitelist( CONF.pci.passthrough_whitelist) self.last_neutron_extension_sync = None self.extensions = {}
def test_clients_glance_cached(self, mock_keystone): mock_keystone.return_value = mock.Mock(session='fake-session') con = mock.MagicMock() obj = clients.OpenStackClients(con) obj._glance = None glance = obj.glance() glance_cached = obj.glance() self.assertEqual(glance, glance_cached)
def create_glanceclient(context): """Creates glance client object. :param context: context to create client object :returns: Glance client object """ osc = clients.OpenStackClients(context) return osc.glance()
def _get_available_network(self, context): neutron = clients.OpenStackClients(context).neutron() search_opts = {'tenant_id': context.project_id, 'shared': False} nets = neutron.list_networks(**search_opts).get('networks', []) if not nets: raise exception.ZunException( _("There is no neutron network available")) nets.sort(key=lambda x: x['created_at']) return nets[0]
def _test_clients_glance(self, expected_region_name, mock_keystone, mock_call): mock_keystone.return_value = mock.Mock(session='fake-session') con = mock.MagicMock() obj = clients.OpenStackClients(con) obj._glance = None obj.glance() mock_call.assert_called_once_with( zun.conf.CONF.glance_client.api_version, session='fake-session')
def test_clients_glance_cached(self, mock_keystone): mock_keystone.return_value.session.get_endpoint.return_value = \ 'glance_url' con = mock.MagicMock() obj = clients.OpenStackClients(con) obj._glance = None glance = obj.glance() glance_cached = obj.glance() self.assertEqual(glance, glance_cached)
def test_clients_glance_cached(self, mock_auth, mock_url): mock_auth.__get__ = mock.Mock(return_value="keystone_url") con = mock.MagicMock() con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155" con.auth_url = "keystone_url" mock_url.return_value = "url_from_keystone" obj = clients.OpenStackClients(con) obj._glance = None glance = obj.glance() glance_cached = obj.glance() self.assertEqual(glance, glance_cached)
def test_clients_glance_noauth(self): con = mock.MagicMock() con.auth_token = None con.auth_token_info = None auth_url = mock.PropertyMock(name="auth_url", return_value="keystone_url") type(con).auth_url = auth_url con.get_url_for = mock.Mock(name="get_url_for") con.get_url_for.return_value = "url_from_keystone" obj = clients.OpenStackClients(con) obj._glance = None self.assertRaises(exception.AuthorizationFailure, obj.glance)
def list_ports(context, container, **kwargs): container_ports = [] if not container.addresses: return container_ports else: port_list = [] neutron_client = clients.OpenStackClients(context).neutron() for ports in container.addresses.values(): port_list.extend([p['port'] for p in ports]) port_set = set(port_list) for port in port_set: container_ports.append(neutron_client.show_port(port)['port']) return container_ports
def test_clients_neturon(self, mock_keystone, mock_call): ca_file = '/testpath' insecure = True zun.conf.CONF.set_override('ca_file', ca_file, group='neutron_client') zun.conf.CONF.set_override('insecure', insecure, group='neutron_client') con = mock.MagicMock() con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155" con.auth_url = "keystone_url" obj = clients.OpenStackClients(con) obj._neutron = None obj.neutron() mock_call.assert_called_once()
def test_zun_url(self, mock_keystone): fake_region = 'fake_region' fake_endpoint = 'fake_endpoint' zun.conf.CONF.set_override('region_name', fake_region, group='zun_client') zun.conf.CONF.set_override('endpoint_type', fake_endpoint, group='zun_client') obj = clients.OpenStackClients(None) obj.zun_url() mock_endpoint = mock_keystone.return_value.session.get_endpoint mock_endpoint.assert_called_once_with(region_name=fake_region, service_type='container', interface=fake_endpoint)
def test_clients_cinder(self, mock_keystone, mock_call): ca_file = '/testpath' insecure = True endpoint_type = 'internalURL' zun.conf.CONF.set_override('ca_file', ca_file, group='cinder_client') zun.conf.CONF.set_override('insecure', insecure, group='cinder_client') zun.conf.CONF.set_override('endpoint_type', endpoint_type, group='cinder_client') con = mock.MagicMock() con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155" con.auth_url = "keystone_url" obj = clients.OpenStackClients(con) obj._cinder = None obj.cinder() mock_call.assert_called_once()
def get_security_group_ids(context, security_groups, **kwargs): if not security_groups: return None else: neutron = clients.OpenStackClients(context).neutron() search_opts = {'tenant_id': context.project_id} security_groups_list = neutron.list_security_groups( **search_opts).get('security_groups', []) security_group_ids = [item['id'] for item in security_groups_list if item['name'] in security_groups or item['id'] in security_groups] if len(security_group_ids) >= len(security_groups): return security_group_ids else: raise exception.ZunException(_( "Any of the security group in %s is not found ") % security_groups)
def _test_clients_glance(self, expected_region_name, mock_auth, mock_url, mock_call): mock_auth.__get__ = mock.Mock(return_value="keystone_url") con = mock.MagicMock() con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155" con.auth_url = "keystone_url" mock_url.return_value = "url_from_keystone" obj = clients.OpenStackClients(con) obj._glance = None obj.glance() mock_call.assert_called_once_with( zun.conf.CONF.glance_client.api_version, endpoint='url_from_keystone', username=None, token='3bcc3d3a03f44e3d8377f9247b0ad155', auth_url='keystone_url', password=None, cacert=None, cert=None, key=None, insecure=False) mock_url.assert_called_once_with(service_type='image', interface='publicURL', region_name=expected_region_name)
def client(self): if not self._client: self._client = clients.OpenStackClients(self.context).nova() return self._client
def _get_admin_client(self): if self.admin_client is None: context = zun_context.get_admin_context() self.admin_client = clients.OpenStackClients(context).neutron() return self.admin_client
def __init__(self, context): self.context = context self.client = clients.OpenStackClients(self.context).neutron() self.admin_client = None
def init(self, context, docker_api): self.docker = docker_api self.neutron = clients.OpenStackClients(context).neutron() self.context = context
def __init__(self, context): self.context = context #LOG.debug('NeutronAPI xxx context=%s' % (context.to_dict())) self.neutron = clients.OpenStackClients(self.context).neutron()
def __init__(self, context): self.context = context self.cinder = clients.OpenStackClients(self.context).cinder()
def __init__(self, context): self.context = context self.neutron = clients.OpenStackClients(self.context).neutron()