Esempio n. 1
0
    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)
Esempio n. 2
0
    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')
Esempio n. 3
0
 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 = {}
Esempio n. 4
0
 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)
Esempio n. 5
0
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()
Esempio n. 6
0
 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]
Esempio n. 7
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')
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
File: utils.py Progetto: zwphit/zun
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
Esempio n. 12
0
 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()
Esempio n. 13
0
    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)
Esempio n. 14
0
 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()
Esempio n. 15
0
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)
Esempio n. 16
0
 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)
Esempio n. 17
0
File: nova.py Progetto: zwphit/zun
 def client(self):
     if not self._client:
         self._client = clients.OpenStackClients(self.context).nova()
     return self._client
Esempio n. 18
0
 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
Esempio n. 19
0
 def __init__(self, context):
     self.context = context
     self.client = clients.OpenStackClients(self.context).neutron()
     self.admin_client = None
Esempio n. 20
0
 def init(self, context, docker_api):
     self.docker = docker_api
     self.neutron = clients.OpenStackClients(context).neutron()
     self.context = context
Esempio n. 21
0
 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()
Esempio n. 23
0
 def __init__(self, context):
     self.context = context
     self.neutron = clients.OpenStackClients(self.context).neutron()