示例#1
0
    def test_delete_router_gateway_as_property(self):
        self._create_router_with_gateway()
        neutronclient.Client.delete_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn(None)

        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndRaise(
                qe.NeutronClientException(status_code=404))

        self.m.ReplayAll()
        t = template_format.parse(neutron_external_gateway_template)
        stack = utils.parse_stack(t)
        rsrc = self.create_router(t, stack, 'router')
        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
        self.m.VerifyAll()
示例#2
0
    def test_update_missing_member(self):
        rsrc = self.create_load_balancer()
        neutronclient.Client.delete_member(u'member5678').AndRaise(
            exceptions.NeutronClientException(status_code=404))

        self.m.ReplayAll()
        scheduler.TaskRunner(rsrc.create)()

        props = dict(rsrc.properties)
        props['members'] = []
        update_template = rsrc.t.freeze(properties=props)

        scheduler.TaskRunner(rsrc.update, update_template)()
        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
示例#3
0
    def test_update_missing_member(self):
        rsrc = self.create_load_balancer()
        self.mc.delete_member.side_effect = [
            exceptions.NeutronClientException(status_code=404)]

        scheduler.TaskRunner(rsrc.create)()

        props = dict(rsrc.properties)
        props['members'] = []
        update_template = rsrc.t.freeze(properties=props)

        scheduler.TaskRunner(rsrc.update, update_template)()
        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.mc.delete_member.assert_called_once_with(u'member5678')
        self.validate_create_load_balancer()
示例#4
0
 def test_create_failed(self):
     self.mock_create.side_effect = exceptions.NeutronClientException()
     snippet = template_format.parse(health_monitor_template)
     self.stack = utils.parse_stack(snippet)
     resource_defns = self.stack.t.resource_definitions(self.stack)
     rsrc = loadbalancer.HealthMonitor(
         'monitor', resource_defns['monitor'], self.stack)
     error = self.assertRaises(exception.ResourceFailure,
                               scheduler.TaskRunner(rsrc.create))
     self.assertEqual(
         'NeutronClientException: resources.monitor: '
         'An unknown exception occurred.',
         str(error))
     self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
     self.mock_create.assert_called_once_with(self.create_snippet)
示例#5
0
    def test_delete_vip_failed(self):
        self.mock_delete_vip.side_effect = exceptions.NeutronClientException(
            status_code=400)

        rsrc = self.create_pool()
        scheduler.TaskRunner(rsrc.create)()
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.delete))
        self.assertEqual(
            'NeutronClientException: resources.pool: '
            'An unknown exception occurred.',
            str(error))
        self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)
        self.mock_delete_vip.assert_called_once_with('xyz')
        self.mock_delete.assert_not_called()
    def create_security_group(self, body=None):
        s = body.get('security_group')
        if len(s.get('name')) > 255 or len(s.get('description')) > 255:
            msg = 'Security Group name great than 255'
            raise n_exc.NeutronClientException(message=msg, status_code=401)
        ret = {
            'name': s.get('name'),
            'description': s.get('description'),
            'tenant_id': 'fake',
            'security_group_rules': [],
            'id': str(uuid.uuid4())
        }

        self._fake_security_groups[ret['id']] = ret
        return {'security_group': ret}
示例#7
0
    def test_delete(self):
        rsrc = self.create_vpnservice()
        neutronclient.Client.show_vpnservice('vpn123').AndReturn(
            {'vpnservice': {
                'status': 'ACTIVE'
            }})

        neutronclient.Client.delete_vpnservice('vpn123')
        neutronclient.Client.show_vpnservice('vpn123').AndRaise(
            exceptions.NeutronClientException(status_code=404))
        self.m.ReplayAll()
        scheduler.TaskRunner(rsrc.create)()
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
    def test_delete_failed(self):
        neutronclient.Client.delete_metering_label_rule('5678').AndRaise(
            exceptions.NeutronClientException(status_code=400))

        rsrc = self.create_metering_label_rule()
        self.m.ReplayAll()
        scheduler.TaskRunner(rsrc.create)()
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.delete))
        self.assertEqual(
            'NeutronClientException: resources.rule: '
            'An unknown exception occurred.',
            six.text_type(error))
        self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()
示例#9
0
    def test_validate(self):
        nc = mock.Mock()
        mock_create = self.patchobject(neutron.NeutronClientPlugin, '_create')
        mock_create.return_value = nc
        mock_find = self.patchobject(neutron.neutronV20,
                                     'find_resourceid_by_name_or_id')
        mock_find.side_effect = ['foo',
                                 qe.NeutronClientException(status_code=404)]

        constraint = self.constraint_class()
        ctx = utils.dummy_context()
        self.assertTrue(constraint.validate("foo", ctx))
        self.assertFalse(constraint.validate("bar", ctx))
        mock_find.assert_has_calls([mock.call(nc, self.resource_type, 'foo'),
                                    mock.call(nc, self.resource_type, 'bar')])
示例#10
0
 def get_auth_info(self):
     # This method is provided for backward compatibility only.
     if not isinstance(self.auth, BaseIdentityPlugin):
         msg = ('Auth info not available. Auth plugin is not an identity '
                'auth plugin.')
         raise exceptions.NeutronClientException(message=msg)
     access_info = self.auth.get_access(self.session)
     endpoint_url = self.auth.get_endpoint(self.session,
                                           service_type=self.service_type,
                                           region_name=self.region_name,
                                           interface=self.interface)
     return {'auth_token': access_info.auth_token,
             'auth_tenant_id': access_info.tenant_id,
             'auth_user_id': access_info.user_id,
             'endpoint_url': endpoint_url}
示例#11
0
    def test_router_interface_with_old_data(self):
        self.stub_SubnetConstraint_validate()
        self.stub_RouterConstraint_validate()
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'router',
            '3e46229d-8fce-4733-819a-b5fe630550f8'
        ).AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            '91e47a57-7508-46fe-afc9-fc454e8580e1'
        ).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
        neutronclient.Client.add_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8',
            {'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
        ).AndReturn(None)
        neutronclient.Client.remove_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8',
            {'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
        ).AndReturn(None)
        neutronclient.Client.remove_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8',
            {'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
        ).AndRaise(qe.NeutronClientException(status_code=404))

        self.m.ReplayAll()
        t = template_format.parse(neutron_template)
        stack = utils.parse_stack(t)

        rsrc = self.create_router_interface(
            t, stack, 'router_interface', properties={
                'router': '3e46229d-8fce-4733-819a-b5fe630550f8',
                'subnet': '91e47a57-7508-46fe-afc9-fc454e8580e1'
            })
        self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8'
                         ':subnet_id=91e47a57-7508-46fe-afc9-fc454e8580e1',
                         rsrc.resource_id)
        (rsrc.resource_id) = ('3e46229d-8fce-4733-819a-b5fe630550f8:'
                              '91e47a57-7508-46fe-afc9-fc454e8580e1')
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8'
                         ':91e47a57-7508-46fe-afc9-fc454e8580e1',
                         rsrc.resource_id)
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
        scheduler.TaskRunner(rsrc.delete)()
        self.m.VerifyAll()
示例#12
0
    def test_subnet_attribute_exception(self):
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            'net1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('net1234')
        neutronclient.Client.create_port({'port': {
            'network_id': u'net1234',
            'name': utils.PhysName('test_stack', 'port'),
            'admin_state_up': True,
            'device_owner': u'network:dhcp'}}
        ).AndReturn({'port': {
            'status': 'BUILD',
            'id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
        }})
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
        ).MultipleTimes().AndReturn({'port': {
            'status': 'DOWN',
            'name': utils.PhysName('test_stack', 'port'),
            'allowed_address_pairs': [],
            'admin_state_up': True,
            'network_id': 'net1234',
            'device_id': 'dc68eg2c-b60g-4b3f-bd82-67ec87650532',
            'mac_address': 'fa:16:3e:75:67:60',
            'tenant_id': '58a61fc3992944ce971404a2ece6ff98',
            'security_groups': ['5b15d80c-6b70-4a1c-89c9-253538c5ade6'],
            'fixed_ips': [{'subnet_id': 'd0e971a6-a6b4-4f4c-8c88-b75e9c120b7e',
                           'ip_address': '10.0.0.2'}]
        }})
        neutronclient.Client.show_subnet(
            'd0e971a6-a6b4-4f4c-8c88-b75e9c120b7e'
        ).AndRaise(qe.NeutronClientException('ConnectionFailed: Connection '
                                             'to neutron failed: Maximum '
                                             'attempts reached'))
        self.m.ReplayAll()

        t = template_format.parse(neutron_port_template)
        t['resources']['port']['properties'].pop('fixed_ips')
        stack = utils.parse_stack(t)
        port = stack['port']
        scheduler.TaskRunner(port.create)()
        self.assertIsNone(port.FnGetAtt('subnets'))
        log_msg = ('Failed to fetch resource attributes: ConnectionFailed: '
                   'Connection to neutron failed: Maximum attempts reached')
        self.assertIn(log_msg, self.LOG.output)
        self.m.VerifyAll()
示例#13
0
    def _test_router_interface(self, resolve_router=True):
        neutronclient.Client.add_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8', {
                'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'
            }).AndReturn(None)
        neutronclient.Client.remove_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8', {
                'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'
            }).AndReturn(None)
        neutronclient.Client.remove_interface_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8', {
                'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'
            }).AndRaise(qe.NeutronClientException(status_code=404))
        t = template_format.parse(neutron_template)
        stack = utils.parse_stack(t)
        self.stub_SubnetConstraint_validate()
        self.stub_RouterConstraint_validate()
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client), 'router',
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn(
                '3e46229d-8fce-4733-819a-b5fe630550f8')
        router_key = 'router'
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client), 'subnet',
            '91e47a57-7508-46fe-afc9-fc454e8580e1').AndReturn(
                '91e47a57-7508-46fe-afc9-fc454e8580e1')
        subnet_key = 'subnet'

        self.m.ReplayAll()
        rsrc = self.create_router_interface(
            t,
            stack,
            'router_interface',
            properties={
                router_key: '3e46229d-8fce-4733-819a-b5fe630550f8',
                subnet_key: '91e47a57-7508-46fe-afc9-fc454e8580e1'
            })

        # Ensure that properties correctly translates
        if not resolve_router:
            self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8',
                             rsrc.properties.get(rsrc.ROUTER))
            self.assertIsNone(rsrc.properties.get(rsrc.ROUTER_ID))

        scheduler.TaskRunner(rsrc.delete)()
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
        scheduler.TaskRunner(rsrc.delete)()
        self.m.VerifyAll()
示例#14
0
 def test_create_failed(self):
     neutronclient.Client.create_ikepolicy(self.IKE_POLICY_CONF).AndRaise(
         exceptions.NeutronClientException())
     self.m.ReplayAll()
     snippet = template_format.parse(ikepolicy_template)
     self.stack = utils.parse_stack(snippet)
     resource_defns = self.stack.t.resource_definitions(self.stack)
     rsrc = vpnservice.IKEPolicy('ikepolicy', resource_defns['IKEPolicy'],
                                 self.stack)
     error = self.assertRaises(exception.ResourceFailure,
                               scheduler.TaskRunner(rsrc.create))
     self.assertEqual(
         'NeutronClientException: An unknown exception occurred.',
         six.text_type(error))
     self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
     self.m.VerifyAll()
示例#15
0
def find_resourceid_by_id(client, resource, resource_id):
    resource_plural = _get_resource_plural(resource, client)
    obj_lister = getattr(client, "list_%s" % resource_plural)
    # perform search by id only if we are passing a valid UUID
    match = re.match(UUID_PATTERN, resource_id)
    collection = resource_plural
    if match:
        data = obj_lister(id=resource_id, fields='id')
        if data and data[collection]:
            return data[collection][0]['id']
    not_found_message = (_("Unable to find %(resource)s with id "
                           "'%(id)s'") %
                         {'resource': resource, 'id': resource_id})
    # 404 is used to simulate server side behavior
    raise exceptions.NeutronClientException(
        message=not_found_message, status_code=404)
示例#16
0
 def test_unbind_neutron_port_failure(self, mock_log, mock_client):
     mock_client.return_value.update_port.side_effect = (
         neutron_client_exc.NeutronClientException())
     body = {
         'port': {
             'binding:host_id': '',
             'binding:profile': {}
         }
     }
     port_id = 'fake-port-id'
     self.assertRaises(exception.NetworkError, neutron.unbind_neutron_port,
                       port_id, context=self.context)
     mock_client.assert_called_once_with(context=self.context)
     mock_client.return_value.update_port.assert_called_once_with(port_id,
                                                                  body)
     mock_log.exception.assert_called_once()
示例#17
0
    def test_create_port_exception_status_409(self):
        # Set up test data
        self.mock_object(
            self.neutron_api.client, 'create_port',
            mock.Mock(side_effect=neutron_client_exc.NeutronClientException(
                status_code=409)))
        port_args = {'tenant_id': 'test tenant', 'network_id': 'test net'}

        # Execute method 'create_port'
        self.assertRaises(exception.PortLimitExceeded,
                          self.neutron_api.create_port, **port_args)

        # Verify results
        self.assertTrue(neutron_api.LOG.exception.called)
        self.assertTrue(clientv20.Client.called)
        self.assertTrue(self.neutron_api.client.create_port.called)
示例#18
0
 def test_neutron_port_update_with_execption(self):
     opts = [{}]
     port_id = 'fake-port-id'
     my_context = context.RequestContext(user='******',
                                         tenant='test-tenant')
     with mock.patch.object(client.Client, "__init__") as mock_client_init:
         mock_client_init.return_value = None
         api = neutron.NeutronAPI(my_context)
         with mock.patch.object(client.Client,
                                "update_port") as mock_update_port:
             mock_update_port.side_effect = (
                 neutron_client_exc.NeutronClientException())
             self.assertRaises(
                     exception.FailedToUpdateDHCPOptOnPort,
                     api.update_port_dhcp_opts,
                     port_id, opts)
示例#19
0
    def mock_create_fail_network_not_found_delete_success(self):
        neutronclient.Client.create_network_gateway({
            'network_gateway': {
                'name':
                u'NetworkGateway',
                'devices': [{
                    'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': u'breth1'
                }]
            }
        }).AndReturn({
            'network_gateway': {
                'id':
                'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'name':
                'NetworkGateway',
                'default':
                False,
                'tenant_id':
                '96ba52dc-c5c5-44c6-9a9d-d3ba1a03f77f',
                'devices': [{
                    'id': 'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': 'breth1'
                }]
            }
        })
        neutronclient.Client.disconnect_network_gateway(
            'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }).AndReturn(None)
        # mock successful to delete the network_gateway
        neutronclient.Client.delete_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37').AndReturn(None)
        neutronclient.Client.show_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37').AndRaise(
                qe.NeutronClientException(status_code=404))

        t = template_format.parse(gw_template)

        self.stack = utils.parse_stack(t)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        rsrc = network_gateway.NetworkGateway('test_network_gateway',
                                              resource_defns['NetworkGateway'],
                                              self.stack)
        return rsrc
示例#20
0
 def test_create_security_group_rules_exceed_quota(self):
     vals = {'protocol': 'tcp', 'cidr': '0.0.0.0/0',
             'parent_group_id': '7ae75663-277e-4a0e-8f87-56ea4e70cb47',
             'group_id': None, 'from_port': 1025, 'to_port': 1025}
     body = {'security_group_rules': [{'remote_group_id': None,
             'direction': 'ingress', 'protocol': 'tcp', 'ethertype': 'IPv4',
             'port_range_max': 1025, 'port_range_min': 1025,
             'security_group_id': '7ae75663-277e-4a0e-8f87-56ea4e70cb47',
             'remote_ip_prefix': '0.0.0.0/0'}]}
     name = 'test-security-group'
     message = "Quota exceeded for resources: ['security_group_rule']"
     self.mocked_client.create_security_group_rule.side_effect = (
         n_exc.NeutronClientException(status_code=409, message=message))
     self.assertRaises(exception.SecurityGroupLimitExceeded,
                       sg_api.add_rules, self.context, None, name, [vals])
     self.mocked_client.create_security_group_rule.assert_called_once_with(
         body)
示例#21
0
 def test_delete_failed(self):
     neutronclient.Client.show_ipsec_site_connection('con123').AndReturn(
         {'ipsec_site_connection': {
             'status': 'ACTIVE'
         }})
     neutronclient.Client.delete_ipsec_site_connection('con123').AndRaise(
         exceptions.NeutronClientException(status_code=400))
     rsrc = self.create_ipsec_site_connection()
     self.m.ReplayAll()
     scheduler.TaskRunner(rsrc.create)()
     error = self.assertRaises(exception.ResourceFailure,
                               scheduler.TaskRunner(rsrc.delete))
     self.assertEqual(
         'NeutronClientException: resources.ipsec_site_connection: '
         'An unknown exception occurred.', six.text_type(error))
     self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)
     self.m.VerifyAll()
示例#22
0
    def test_delete_already_gone(self):
        rsrc = self.create_vpnservice()
        self.mockclient.show_vpnservice.return_value = {
            'vpnservice': {'status': 'ACTIVE'}
        }
        self.mockclient.delete_vpnservice.side_effect = (
            exceptions.NeutronClientException(status_code=404))

        scheduler.TaskRunner(rsrc.create)()
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.mockclient.create_vpnservice.assert_called_once_with(
            self.VPN_SERVICE_CONF)
        self.mockclient.show_vpnservice.assert_called_once_with('vpn123')
        self.mockclient.delete_vpnservice.assert_called_once_with(
            'vpn123')
示例#23
0
    def test_delete_failed(self):
        rsrc = self.create_ipsecpolicy()
        self.mockclient.delete_ipsecpolicy.side_effect = (
            exceptions.NeutronClientException(status_code=400))

        scheduler.TaskRunner(rsrc.create)()
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.delete))
        self.assertEqual(
            'NeutronClientException: resources.ipsecpolicy: '
            'An unknown exception occurred.', six.text_type(error))
        self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)

        self.mockclient.create_ipsecpolicy.assert_called_once_with(
            self.IPSEC_POLICY_CONF)
        self.mockclient.delete_ipsecpolicy.assert_called_once_with('ips123')
        self.mockclient.show_ipsecpolicy.assert_not_called()
示例#24
0
 def args2body(self, parsed_args):
     body = {
         self.resource: {},
     }
     if parsed_args.template_file:
         if os.path.isfile(parsed_args.template_file):
             tpl_files, template = template_utils.get_template_contents(
                 parsed_args.template_file)
             parsed_args.config = json.dumps(template)
         else:
             raise exc.NeutronClientException("File %s does not exist. "
                                              "Please check the path" %
                                              parsed_args.template_file)
     neutronV20.update_dict(parsed_args, body[self.resource], [
         'name', 'service_type', 'config', 'tenant_id', 'param_names',
         'description'
     ])
     return body
示例#25
0
 def test_create_failed(self):
     neutronclient.Client.create_ipsec_site_connection(
         self.IPSEC_SITE_CONNECTION_CONF).AndRaise(
             exceptions.NeutronClientException())
     self.m.ReplayAll()
     snippet = template_format.parse(ipsec_site_connection_template)
     self.stack = utils.parse_stack(snippet)
     resource_defns = self.stack.t.resource_definitions(self.stack)
     rsrc = vpnservice.IPsecSiteConnection(
         'ipsec_site_connection', resource_defns['IPsecSiteConnection'],
         self.stack)
     error = self.assertRaises(exception.ResourceFailure,
                               scheduler.TaskRunner(rsrc.create))
     self.assertEqual(
         'NeutronClientException: An unknown exception occurred.',
         six.text_type(error))
     self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
     self.m.VerifyAll()
示例#26
0
 def take_action(self, parsed_args):
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     subnet = None
     router = None
     if not parsed_args.subnet and not parsed_args.router:
         message = (_('--subnet or --router option should be specified'))
         raise exceptions.NeutronClientException(message=message)
     if parsed_args.subnet:
         subnet = neutronV20.find_resourceid_by_name_or_id(
             self.get_client(), 'subnet', parsed_args.subnet)
         self.values_specs.append('--subnet=%s' % subnet)
     if parsed_args.router:
         router = neutronV20.find_resourceid_by_name_or_id(
             self.get_client(), 'router', parsed_args.router)
         self.values_specs.append('--router=%s' % router)
     resp = super(ListRedirectTarget, self).take_action(parsed_args)
     return resp
示例#27
0
    def test_delete_already_gone(self):
        self.mockclient.show_ipsec_site_connection.return_value = {
            'ipsec_site_connection': {'status': 'ACTIVE'}
        }
        self.mockclient.delete_ipsec_site_connection.side_effect = (
            exceptions.NeutronClientException(status_code=404))
        rsrc = self.create_ipsec_site_connection()

        scheduler.TaskRunner(rsrc.create)()
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.mockclient.create_ipsec_site_connection.assert_called_once_with(
            self.IPSEC_SITE_CONNECTION_CONF)
        self.mockclient.show_ipsec_site_connection.assert_called_once_with(
            'con123')
        self.mockclient.delete_ipsec_site_connection.assert_called_once_with(
            'con123')
    def test_delete_already_gone(self):
        rsrc = self.create_metering_label()
        self.mockclient.delete_metering_label.side_effect = (
            exceptions.NeutronClientException(status_code=404))

        scheduler.TaskRunner(rsrc.create)()
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.mockclient.create_metering_label.assert_called_once_with({
            'metering_label': {
                'name': 'TestLabel',
                'description': 'Description of TestLabel',
                'shared': True
            }
        })
        self.mockclient.delete_metering_label.assert_called_once_with('1234')
        self.mockclient.show_metering_label.assert_not_called()
示例#29
0
    def test_check_for_neutron_tag_support_with_legacy_ext(
            self, ext_matrix, mock_extension):
        err = n_exceptions.NotFound.status_code
        ext_not_found_ex = n_exceptions.NeutronClientException(status_code=err,
                                                               message="")

        def mock_fn(ext):
            if not ext_matrix.get(ext, False):
                raise ext_not_found_ex

        mock_extension.side_effect = mock_fn
        controllers.check_for_neutron_tag_support()
        mock_extension.assert_any_call('standard-attr-tag')
        mock_extension.assert_any_call('tag')
        mock_extension.assert_any_call('tag-ext')

        self.assertEqual(controllers.app.tag, ext_matrix['tag'])
        self.assertEqual(controllers.app.tag_ext, ext_matrix['tag-ext'])
示例#30
0
def _find_resourceid_by_name(client, resource, name):
    resource_plural = _get_resource_plural(resource, client)
    obj_lister = getattr(client, "list_%s" % resource_plural)
    data = obj_lister(name=name, fields='id')
    collection = resource_plural
    info = data[collection]
    if len(info) > 1:
        raise exceptions.NeutronClientNoUniqueMatch(resource=resource,
                                                    name=name)
    elif len(info) == 0:
        not_found_message = (_("Unable to find %(resource)s with name "
                               "'%(name)s'") %
                             {'resource': resource, 'name': name})
        # 404 is used to simulate server side behavior
        raise exceptions.NeutronClientException(
            message=not_found_message, status_code=404)
    else:
        return info[0]['id']