Example #1
0
    def mock_create_fail_network_not_found_delete_success(self):
        self.mockclient.create_network_gateway.return_value = {
            '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'
                }]
            }
        }
        self.mockclient.connect_network_gateway.side_effect = (
            qe.NeutronClientException)
        self.mockclient.disconnect_network_gateway.return_value = None
        # mock successful to delete the network_gateway
        self.mockclient.delete_network_gateway.return_value = None
        self.mockclient.show_network_gateway.side_effect = (
            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
    def test_network_gatway_create_failed(self):
        neutronclient.Client.create_network_gateway({
            'network_gateway': {
                'name':
                u'NetworkGateway',
                'devices': [{
                    'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': u'breth1'
                }]
            }
        }).AndRaise(qe.NeutronClientException)
        self.stub_NetworkConstraint_validate()

        self.m.ReplayAll()

        t = template_format.parse(gw_template)
        stack = utils.parse_stack(t)
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = network_gateway.NetworkGateway('network_gateway',
                                              resource_defns['NetworkGateway'],
                                              stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'NeutronClientException: resources.network_gateway: '
            'An unknown exception occurred.', six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
    def prepare_create_network_gateway(self, resolve_neutron=True):
        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.connect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }).AndReturn({
                'connection_info': {
                    'network_gateway_id':
                    u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                    'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                    'port_id': u'32acc49c-899e-44ea-8177-6f4157e12eb4'
                }
            })
        self.stub_NetworkConstraint_validate()
        if resolve_neutron:
            neutronV20.find_resourceid_by_name_or_id(
                mox.IsA(neutronclient.Client),
                'network',
                '6af055d3-26f6-48dd-a597-7611d7e58d35',
                cmd_resource=None,
            ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
            t = template_format.parse(gw_template)
        else:
            t = template_format.parse(gw_template_deprecated)

        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
    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'
                }]
            }
        })

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35',
            cmd_resource=None,
        ).MultipleTimes().AndRaise(qe.NeutronClientException(status_code=404))
        # 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
Example #5
0
    def test_gateway_validate_failed_with_vlan(self):
        t = template_format.parse(gw_template)
        del t['resources']['NetworkGateway']['properties']['connections'][0][
            'segmentation_id']
        stack = utils.parse_stack(t)
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = network_gateway.NetworkGateway('test_network_gateway',
                                              resource_defns['NetworkGateway'],
                                              stack)
        self.stub_NetworkConstraint_validate()

        error = self.assertRaises(exception.StackValidationFailed,
                                  scheduler.TaskRunner(rsrc.validate))

        self.assertEqual('segmentation_id must be specified for using vlan',
                         six.text_type(error))
Example #6
0
    def test_gateway_validate_failed_with_flat(self):
        t = template_format.parse(gw_template)
        t['Resources']['NetworkGateway']['Properties']['connections'][0][
            'segmentation_type'] = 'flat'
        stack = utils.parse_stack(t)
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = network_gateway.NetworkGateway('test_network_gateway',
                                              resource_defns['NetworkGateway'],
                                              stack)
        self.stub_NetworkConstraint_validate()

        self.m.ReplayAll()

        error = self.assertRaises(exception.StackValidationFailed,
                                  scheduler.TaskRunner(rsrc.validate))

        self.assertEqual(
            'segmentation_id cannot be specified except 0 for using flat',
            six.text_type(error))

        self.m.VerifyAll()
Example #7
0
    def prepare_create_network_gateway(self, resolve_neutron=True):
        self.mockclient.create_network_gateway.return_value = {
            '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'
                }]
            }
        }
        self.mockclient.connect_network_gateway.return_value = {
            'connection_info': {
                'network_gateway_id': 'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'network_id': '6af055d3-26f6-48dd-a597-7611d7e58d35',
                'port_id': '32acc49c-899e-44ea-8177-6f4157e12eb4'
            }
        }
        self.stub_NetworkConstraint_validate()
        if resolve_neutron:
            t = template_format.parse(gw_template)
        else:
            t = template_format.parse(gw_template_deprecated)

        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