Example #1
0
    def test_show(self):
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/show')
        req.method = 'POST'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context

        result = attachments.show(req, FAKE_UUID1, FAKE_PORT_ID1)
        self.assertEqual(self.expected_show, result)
Example #2
0
    def test_show_invalid(self):
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/show')
        req.method = 'POST'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context

        self.assertRaises(exc.HTTPNotFound, attachments.show, req, FAKE_UUID2,
                          FAKE_PORT_ID1)
 def test_attach_interface_without_network_id(self):
     self.stubs.Set(compute_api.API, 'attach_interface',
                    fake_attach_interface)
     attachments = attach_interfaces.InterfaceAttachmentController()
     req = webob.Request.blank('/v2/fake/os-interfaces/attach')
     req.method = 'POST'
     req.body = jsonutils.dumps({})
     req.headers['content-type'] = 'application/json'
     req.environ['nova.context'] = self.context
     result = attachments.create(req, FAKE_UUID1, jsonutils.loads(req.body))
     self.assertEqual(result['interfaceAttachment']['net_id'], FAKE_NET_ID1)
Example #4
0
    def test_delete_interface_not_found(self):
        self.stubs.Set(compute_api.API, 'detach_interface',
                       fake_detach_interface)
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/delete')
        req.method = 'POST'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context

        self.assertRaises(exc.HTTPNotFound, attachments.delete, req,
                          FAKE_UUID1, 'invaid-port-id')
Example #5
0
    def test_delete(self):
        self.stubs.Set(compute_api.API, 'detach_interface',
                       fake_detach_interface)
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/delete')
        req.method = 'POST'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context

        result = attachments.delete(req, FAKE_UUID1, FAKE_PORT_ID1)
        self.assertEqual('202 Accepted', result.status)
Example #6
0
 def test_attach_interface_with_invalid_data(self):
     self.stubs.Set(compute_api.API, 'attach_interface',
                    fake_attach_interface)
     attachments = attach_interfaces.InterfaceAttachmentController()
     req = webob.Request.blank('/v2/fake/os-interfaces/attach')
     req.method = 'POST'
     req.body = jsonutils.dumps({'interfaceAttachment':
                                 {'net_id': 'bad_id'}})
     req.headers['content-type'] = 'application/json'
     req.environ['nova.context'] = self.context
     self.assertRaises(exc.HTTPBadRequest,
                       attachments.create, req, FAKE_UUID1,
                       jsonutils.loads(req.body))
    def test_attach_interface_instance_locked(self):
        def fake_attach_interface_to_locked_server(self, context, instance,
                                                   network_id, port_id,
                                                   requested_ip):
            raise exception.InstanceIsLocked(instance_uuid=FAKE_UUID1)

        self.stubs.Set(compute_api.API, 'attach_interface',
                       fake_attach_interface_to_locked_server)
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/attach')
        req.method = 'POST'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context
        self.assertRaises(exc.HTTPConflict, attachments.create, req,
                          FAKE_UUID1, jsonutils.loads(req.body))
Example #8
0
 def test_attach_interface_fixed_ip_already_in_use(self, attach_mock,
                                                   get_mock):
     get_mock.side_effect = fake_get_instance
     attach_mock.side_effect = exception.FixedIpAlreadyInUse(
         address='10.0.2.2', instance_uuid=FAKE_UUID1)
     attachments = attach_interfaces.InterfaceAttachmentController()
     req = webob.Request.blank('/v2/fake/os-interfaces/attach')
     req.method = 'POST'
     req.body = jsonutils.dumps({})
     req.headers['content-type'] = 'application/json'
     req.environ['nova.context'] = self.context
     self.assertRaises(exc.HTTPBadRequest, attachments.create, req,
                       FAKE_UUID1, jsonutils.loads(req.body))
     attach_mock.assert_called_once_with(self.context, {}, None, None, None)
     get_mock.assert_called_once_with(self.context,
                                      FAKE_UUID1,
                                      want_objects=True)
Example #9
0
    def test_detach_interface_with_invalid_state(self):
        def fake_detach_interface_invalid_state(*args, **kwargs):
            raise exception.InstanceInvalidState(instance_uuid='',
                                                 attr='',
                                                 state='',
                                                 method='detach_interface')

        self.stubs.Set(compute_api.API, 'detach_interface',
                       fake_detach_interface_invalid_state)
        attachments = attach_interfaces.InterfaceAttachmentController()
        req = webob.Request.blank('/v2/fake/os-interfaces/attach')
        req.method = 'DELETE'
        req.body = jsonutils.dumps({})
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context
        self.assertRaises(exc.HTTPConflict, attachments.delete, req,
                          FAKE_UUID1, FAKE_NET_ID1)