Beispiel #1
0
 def test_admin_token_updated(self):
     CONF.set_override('neutron_server_url',
                       'http://anyhost',
                       group='neutron')
     CONF.set_override('url_timeout', 30, group='neutron')
     token_store = neutronclient.AdminTokenStore.get()
     token_store.admin_auth_token = 'new_token'
     tokens = [{'auth_token': 'new_token1'}, {'auth_token': 'new_token'}]
     my_context = context.ContextBase('userid',
                                      'my_tenantid',
                                      auth_token='token')
     with contextlib.nested(
             mock.patch.object(client.Client,
                               "list_networks",
                               side_effect=mock.Mock),
             mock.patch.object(client.Client,
                               'get_auth_info',
                               side_effect=tokens.pop),
     ):
         client1 = neutronclient.get_client(my_context, True)
         client1.list_networks(retrieve_all=False)
         self.assertEqual('new_token', token_store.admin_auth_token)
         client1 = neutronclient.get_client(my_context, True)
         client1.list_networks(retrieve_all=False)
         self.assertEqual('new_token1', token_store.admin_auth_token)
 def test_reuse_admin_token(self):
     CONF.set_override("neutron_server_url", "http://anyhost", group="neutron")
     CONF.set_override("url_timeout", 30, group="neutron")
     token_store = neutronclient.AdminTokenStore.get()
     token_store.admin_auth_token = "new_token"
     my_context = context.ContextBase("userid", "my_tenantid", auth_token="token")
     with mock.patch.object(client.Client, "list_networks", side_effect=mock.Mock):
         with mock.patch.object(client.Client, "get_auth_info", return_value={"auth_token": "new_token1"}):
             client1 = neutronclient.get_client(my_context, True)
             client1.list_networks(retrieve_all=False)
             self.assertEqual("new_token1", token_store.admin_auth_token)
             client1 = neutronclient.get_client(my_context, True)
             client1.list_networks(retrieve_all=False)
             self.assertEqual("new_token1", token_store.admin_auth_token)
Beispiel #3
0
 def _list_resources(self, context, resource, filters=None):
     filters = filters or {}
     resources = resource + 's'
     action = 'list_' + resources
     neutron = client.get_client(context)
     obj_lister = getattr(neutron, action)
     return obj_lister(**filters)[resources]
    def test_withtoken_context_is_admin(self):
        CONF.set_override("neutron_server_url", "http://anyhost", group="neutron")
        CONF.set_override("url_timeout", 30, group="neutron")
        my_context = context.ContextBase("userid", "my_tenantid", auth_token="token", is_admin=True)
        cl = neutronclient.get_client(my_context)

        self.assertEqual(CONF.neutron.neutron_server_url, cl.httpclient.endpoint_url)
        self.assertEqual(my_context.auth_token, cl.httpclient.auth_token)
        self.assertEqual(CONF.neutron.url_timeout, cl.httpclient.timeout)
    def test_withtoken(self):
        CONF.set_override('neutron_server_url',
                          'http://anyhost',
                          group='neutron')
        CONF.set_override('url_timeout', 30, group='neutron')
        my_context = context.ContextBase('userid',
                                         'my_tenantid',
                                         auth_token='token')
        cl = neutronclient.get_client(my_context)

        self.assertEqual(CONF.neutron.neutron_server_url,
                         cl.httpclient.endpoint_url)
        self.assertEqual(my_context.auth_token, cl.httpclient.auth_token)
        self.assertEqual(CONF.neutron.url_timeout, cl.httpclient.timeout)
 def test_reuse_admin_token(self):
     CONF.set_override('neutron_server_url',
                       'http://anyhost',
                       group='neutron')
     CONF.set_override('url_timeout',
                       30,
                       group='neutron')
     token_store = neutronclient.AdminTokenStore.get()
     token_store.admin_auth_token = 'new_token'
     my_context = context.ContextBase('userid', 'my_tenantid',
                                      auth_token='token')
     with contextlib.nested(
         mock.patch.object(client.Client, "list_networks",
                           side_effect=mock.Mock),
         mock.patch.object(client.Client, 'get_auth_info',
                           return_value={'auth_token': 'new_token1'}),
     ):
         client1 = neutronclient.get_client(my_context, True)
         client1.list_networks(retrieve_all=False)
         self.assertEqual('new_token1', token_store.admin_auth_token)
         client1 = neutronclient.get_client(my_context, True)
         client1.list_networks(retrieve_all=False)
         self.assertEqual('new_token1', token_store.admin_auth_token)
    def test_withtoken(self):
        CONF.set_override('neutron_server_url',
                          'http://anyhost',
                          group='neutron')
        CONF.set_override('url_timeout',
                          30,
                          group='neutron')
        my_context = context.ContextBase('userid',
                                         'my_tenantid',
                                         auth_token='token')
        cl = neutronclient.get_client(my_context)

        self.assertEqual(CONF.neutron.neutron_server_url,
                         cl.httpclient.endpoint_url)
        self.assertEqual(my_context.auth_token,
                         cl.httpclient.auth_token)
        self.assertEqual(CONF.neutron.url_timeout, cl.httpclient.timeout)
Beispiel #8
0
 def _delete_resource(self, context, resource, resource_id):
     action = 'delete_' + resource
     neutron = client.get_client(context)
     obj_deleter = getattr(neutron, action)
     obj_deleter(resource_id)
Beispiel #9
0
 def _update_resource(self, context, resource, resource_id, attrs):
     action = 'update_' + resource
     neutron = client.get_client(context)
     obj_updater = getattr(neutron, action)
     return obj_updater(resource_id, attrs)[resource]
Beispiel #10
0
 def _show_resource(self, context, resource, resource_id):
     action = 'show_' + resource
     neutron = client.get_client(context)
     obj_method = getattr(neutron, action)
     return obj_method(resource_id)[resource]
Beispiel #11
0
 def _create_resource(self, context, resource, attrs):
     action = 'create_' + resource
     neutron = client.get_client(context)
     obj_creator = getattr(neutron, action)
     return obj_creator(attrs)[resource]
Beispiel #12
0
 def remove_router_interface(self, context, router_id, interface):
     return client.get_client(context).remove_interface_router(router_id,
                                                               interface)
Beispiel #13
0
 def add_router_interface(self, context, router_id, interface):
     return client.get_client(context).add_interface_router(router_id,
                                                            interface)