def test_add_associated_floating_ip_to_instance(self):
        def fake_fixed_ip_get_by_address(ctx, address, session=None):
            return {'address': address, 'network': {'multi_host': None,
                                                    'host': 'fake'}}

        self.disassociated = False

        def fake_network_api_disassociate(local_self, ctx, floating_address):
            self.disassociated = True

        db.floating_ip_update(self.context, self.address, {'project_id': '123',
                                                           'fixed_ip_id': 1})
        self.stubs.Set(network.api.API, "disassociate_floating_ip",
                       fake_network_api_disassociate)
        self.stubs.Set(db.api, "fixed_ip_get_by_address",
                       fake_fixed_ip_get_by_address)

        body = dict(addFloatingIp=dict(address=self.address))
        req = webob.Request.blank('/v1.1/123/servers/test_inst/action')
        req.method = "POST"
        req.body = json.dumps(body)
        req.headers["content-type"] = "application/json"

        resp = req.get_response(fakes.wsgi_app())
        self.assertEqual(resp.status_int, 202)
        self.assertTrue(self.disassociated)
Beispiel #2
0
    def test_add_associated_floating_ip_to_instance(self):
        def fake_fixed_ip_get_by_address(ctx, address, session=None):
            return {
                'address': address,
                'network': {
                    'multi_host': None,
                    'host': 'fake'
                }
            }

        self.disassociated = False

        def fake_network_api_disassociate(local_self, ctx, floating_address):
            self.disassociated = True

        db.floating_ip_update(self.context, self.address, {
            'project_id': '123',
            'fixed_ip_id': 1
        })
        self.stubs.Set(network.api.API, "disassociate_floating_ip",
                       fake_network_api_disassociate)
        self.stubs.Set(db.api, "fixed_ip_get_by_address",
                       fake_fixed_ip_get_by_address)

        body = dict(addFloatingIp=dict(address=self.address))
        req = webob.Request.blank('/v1.1/123/servers/test_inst/action')
        req.method = "POST"
        req.body = json.dumps(body)
        req.headers["content-type"] = "application/json"

        resp = req.get_response(fakes.wsgi_app())
        self.assertEqual(resp.status_int, 202)
        self.assertTrue(self.disassociated)
 def test_associate_floating_ip_to_instance_wrong_project_id(self):
     def fake_fixed_ip_get_by_address(ctx, address, session=None):
         return {'address': address, 'network': {'multi_host': None,
                                                 'host': 'fake'}}
     self.stubs.Set(db.api, "fixed_ip_get_by_address",
                    fake_fixed_ip_get_by_address)
     db.floating_ip_update(self.context, self.address, {'project_id': 'bad',
                                                        'fixed_ip_id': 1})
     body = dict(addFloatingIp=dict(address=self.address))
     req = webob.Request.blank('/v1.1/123/servers/test_inst/action')
     req.method = "POST"
     req.body = json.dumps(body)
     req.headers["content-type"] = "application/json"
     resp = req.get_response(fakes.wsgi_app())
     self.assertEqual(resp.status_int, 401)
Beispiel #4
0
 def save(self, context):
     updates = self.obj_get_changes()
     if 'address' in updates:
         raise exception.ObjectActionError(action='save',
                                           reason='address is not mutable')
     db_floatingip = db.floating_ip_update(context, str(self.address),
                                           updates)
     self._from_db_object(context, self, db_floatingip)
 def save(self, context):
     updates = self.obj_get_changes()
     if 'address' in updates:
         raise exception.ObjectActionError(action='save',
                                           reason='address is not mutable')
     db_floatingip = db.floating_ip_update(context, str(self.address),
                                           updates)
     self._from_db_object(context, self, db_floatingip)
Beispiel #6
0
    def test_associate_floating_ip_to_instance_wrong_project_id(self):
        def fake_fixed_ip_get_by_address(ctx, address, session=None):
            return {
                'address': address,
                'network': {
                    'multi_host': None,
                    'host': 'fake'
                }
            }

        self.stubs.Set(db.api, "fixed_ip_get_by_address",
                       fake_fixed_ip_get_by_address)
        db.floating_ip_update(self.context, self.address, {
            'project_id': 'bad',
            'fixed_ip_id': 1
        })
        body = dict(addFloatingIp=dict(address=self.address))
        req = webob.Request.blank('/v1.1/123/servers/test_inst/action')
        req.method = "POST"
        req.body = json.dumps(body)
        req.headers["content-type"] = "application/json"
        resp = req.get_response(fakes.wsgi_app())
        self.assertEqual(resp.status_int, 400)
Beispiel #7
0
    def save(self, context):
        updates = self.obj_get_changes()
        if "address" in updates:
            raise exception.ObjectActionError(action="save", reason="address is not mutable")
        if "fixed_ip_id" in updates:
            reason = "fixed_ip_id is not mutable"
            raise exception.ObjectActionError(action="save", reason=reason)

        # NOTE(danms): Make sure we don't pass the calculated fixed_ip
        # relationship to the DB update method
        updates.pop("fixed_ip", None)

        db_floatingip = db.floating_ip_update(context, str(self.address), updates)
        self._from_db_object(context, self, db_floatingip)
Beispiel #8
0
    def save(self):
        updates = self.obj_get_changes()
        if 'address' in updates:
            raise exception.ObjectActionError(action='save',
                                              reason='address is not mutable')
        if 'fixed_ip_id' in updates:
            reason = 'fixed_ip_id is not mutable'
            raise exception.ObjectActionError(action='save', reason=reason)

        # NOTE(danms): Make sure we don't pass the calculated fixed_ip
        # relationship to the DB update method
        updates.pop('fixed_ip', None)

        db_floatingip = db.floating_ip_update(self._context, str(self.address),
                                              updates)
        self._from_db_object(self._context, self, db_floatingip)
Beispiel #9
0
    def save(self):
        updates = self.obj_get_changes()
        if 'address' in updates:
            raise exception.ObjectActionError(action='save',
                                              reason='address is not mutable')
        if 'fixed_ip_id' in updates:
            reason = 'fixed_ip_id is not mutable'
            raise exception.ObjectActionError(action='save', reason=reason)

        # NOTE(danms): Make sure we don't pass the calculated fixed_ip
        # relationship to the DB update method
        updates.pop('fixed_ip', None)

        db_floatingip = db.floating_ip_update(self._context, str(self.address),
                                              updates)
        self._from_db_object(self._context, self, db_floatingip)