Exemple #1
0
    def test_get_instance_works(self):
        instances.fetch_instance(u'VMID').AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        rv = self.client.get('/v1/instances/VMID')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, 'REPLY')
    def test_get_instance_works(self):
        instances.fetch_instance(u'VMID').AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        rv = self.client.get('/v1/instances/VMID')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, 'REPLY')
Exemple #3
0
    def test_remove_instance_not_found(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete().AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/remove' % s.id, {},
                      expected_status_code=404)
    def test_vnc_not_found(self):
        s = self.server
        instances.fetch_instance(s.id)\
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/vnc' % s.id, {},
                      expected_status_code=404)
Exemple #5
0
    def test_rename_not_found(self):
        params = {'name': u'new name'}

        instances.fetch_instance(self.instance_id).AndReturn(self.server)
        self.server.update(name=u'new name') \
                .AndRaise(osc_exc.NotFound('failure'))
        self.mox.ReplayAll()
        self.interact(params, expected_status_code=404)
Exemple #6
0
    def test_vnc_not_found(self):
        s = self.server
        instances.fetch_instance(s.id)\
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/vnc' % s.id, {},
                      expected_status_code=404)
    def test_remove_instance_not_found(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete().AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/remove' % s.id, {},
                      expected_status_code=404)
    def test_rename_not_found(self):
        params = { 'name': u'new name' }

        instances.fetch_instance(self.instance_id).AndReturn(self.server)
        self.server.update(name=u'new name') \
                .AndRaise(osc_exc.NotFound('failure'))
        self.mox.ReplayAll()
        self.interact(params, expected_status_code=404)
    def test_update_empty(self):
        params = {}

        instances.fetch_instance(self.instance_id).AndReturn('VM')
        instances._instance_to_view('VM').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Exemple #10
0
    def test_vnc_late_not_found(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.get_vnc_console(console_type='novnc')\
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/vnc' % s.id, {},
                      expected_status_code=404)
    def test_vnc_late_not_found(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.get_vnc_console(console_type='novnc')\
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/vnc' % s.id, {},
                      expected_status_code=404)
Exemple #12
0
    def test_update_empty(self):
        params = {}

        instances.fetch_instance(self.instance_id).AndReturn('VM')
        instances._instance_to_view('VM').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
    def test_delete_instance_pretends_waiting(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndReturn(s)

        self.mox.ReplayAll()
        rv = self.client.delete('/v1/instances/%s' % s.id)
        self.check_and_parse_response(rv, status_code=202)
Exemple #14
0
    def test_console_output_late_not_found(self):
        s = self.server

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_console_output(length=None) \
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/console-output' % s.id, {},
                      expected_status_code=404)
Exemple #15
0
    def test_reset_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.reboot(REBOOT_HARD)
        instances.fetch_instance(s.id).AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/reset' % s.id, {})
        self.assertEquals(data, 'REPLY')
    def test_reset_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.reboot(REBOOT_HARD)
        instances.fetch_instance(s.id).AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/reset' % s.id, {})
        self.assertEquals(data, 'REPLY')
Exemple #17
0
    def test_delete_instance_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndRaise(NotFound())

        self.mox.ReplayAll()
        rv = self.client.delete('/v1/instances/%s' % s.id)
        self.check_and_parse_response(rv, status_code=204)
    def test_console_output_late_not_found(self):
        s = self.server

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_console_output(length=None) \
                .AndRaise(osc_exc.NotFound('failure'))

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/console-output' % s.id, {},
                      expected_status_code=404)
Exemple #19
0
    def test_delete_instance_pretends_waiting(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndReturn(s)

        self.mox.ReplayAll()
        rv = self.client.delete('/v1/instances/%s' % s.id)
        self.check_and_parse_response(rv, status_code=202)
    def test_delete_instance_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndRaise(NotFound())

        self.mox.ReplayAll()
        rv = self.client.delete('/v1/instances/%s' % s.id)
        self.check_and_parse_response(rv, status_code=204)
    def test_remove_instance_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/remove' % s.id, {})
        self.assertEquals(data, 'REPLY')
Exemple #22
0
    def test_rename_works(self):
        params = {'name': u'new name'}

        instances.fetch_instance(self.instance_id).AndReturn(self.server)
        self.server.update(name=u'new name')
        instances.fetch_instance(self.instance_id).AndReturn('VM')
        instances._instance_to_view('VM').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
    def test_remove_instance_fast(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id)\
                .AndRaise(NotFound())

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/remove' % s.id, {},
                      expected_status_code=204)
    def test_rename_works(self):
        params = { 'name': u'new name' }

        instances.fetch_instance(self.instance_id).AndReturn(self.server)
        self.server.update(name=u'new name')
        instances.fetch_instance(self.instance_id).AndReturn('VM')
        instances._instance_to_view('VM').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Exemple #25
0
    def test_remove_instance_works(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id).AndReturn('VM1')
        instances._instance_to_view('VM1').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/remove' % s.id, {})
        self.assertEquals(data, 'REPLY')
Exemple #26
0
    def test_remove_instance_fast(self):
        s = self.server
        instances.fetch_instance(s.id).AndReturn(s)
        s.delete()
        instances.InstanceDataDAO.delete(s.id)
        instances.fetch_instance(s.id)\
                .AndRaise(NotFound())

        self.mox.ReplayAll()
        self.interact('/v1/instances/%s/remove' % s.id, {},
                      expected_status_code=204)
Exemple #27
0
def _security_groups_for_server(instance_id):
    try:
        result = admin_client_set().compute.security_groups._list(
            '/servers/%s/os-security-groups' % instance_id, 'security_groups')
    except osc_exc.HttpException:
        fetch_instance(instance_id)  # check that server exists and is visible
        raise  # if server exists, re-raise: it was other error
    if not result:
        fetch_instance(instance_id)  # check that server exists and is visible
    else:
        assert_admin_or_project_user(result[0].tenant_id, eperm_status=404)
    return result
def _security_groups_for_server(instance_id):
    try:
        result = admin_client_set().compute.security_groups._list(
            '/servers/%s/os-security-groups' % instance_id,
            'security_groups')
    except osc_exc.HttpException:
        fetch_instance(instance_id)  # check that server exists and is visible
        raise  # if server exists, re-raise: it was other error
    if not result:
        fetch_instance(instance_id)  # check that server exists and is visible
    else:
        assert_admin_or_project_user(result[0].tenant_id, eperm_status=404)
    return result
Exemple #29
0
    def test_update_remind(self):
        params = {'remind-at': u'2013-02-17T15:36:00Z'}
        server = doubles.make(self.mox, doubles.Server, id='VMID')

        instances.fetch_instance(self.instance_id).AndReturn(server)
        instances.InstanceDataDAO.update('VMID',
                                         remind_at=datetime(
                                             2013, 2, 17, 15, 36, 0))
        instances._instance_to_view(server).AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Exemple #30
0
    def test_update_never_expires_and_remind(self):
        params = {'expires-at': None, 'remind-at': None}
        server = doubles.make(self.mox, doubles.Server, id='VMID')

        instances.fetch_instance(self.instance_id).AndReturn(server)
        instances.InstanceDataDAO.update('VMID',
                                         expires_at=None,
                                         remind_at=None)
        instances._instance_to_view(server).AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
    def test_update_remind(self):
        params = {
            'remind-at': u'2013-02-17T15:36:00Z'
        }
        server = doubles.make(self.mox, doubles.Server, id='VMID')

        instances.fetch_instance(self.instance_id).AndReturn(server)
        instances.InstanceDataDAO.update('VMID',
                             remind_at=datetime(2013, 2, 17, 15, 36, 0))
        instances._instance_to_view(server).AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
    def test_update_never_expires_and_remind(self):
        params = {
            'expires-at': None,
            'remind-at': None
        }
        server = doubles.make(self.mox, doubles.Server, id='VMID')

        instances.fetch_instance(self.instance_id).AndReturn(server)
        instances.InstanceDataDAO.update('VMID', expires_at=None,
                                         remind_at=None)
        instances._instance_to_view(server).AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Exemple #33
0
    def test_console_output_works(self):
        s = self.server
        expected = {
            'instance': {
                'id': s.id,
                'name': s.name,
                'href': '/v1/instances/%s' % s.id
            },
            'console-output': 'CONSOLE LOG'
        }

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_console_output(length=None).AndReturn('CONSOLE LOG')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/console-output' % s.id, {})
        self.assertEquals(expected, data)
    def test_console_output_works(self):
        s = self.server
        expected = {
            'instance': {
                'id': s.id,
                'name': s.name,
                'href': '/v1/instances/%s' % s.id
            },
            'console-output': 'CONSOLE LOG'
        }

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_console_output(length=None).AndReturn('CONSOLE LOG')

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/console-output' % s.id, {})
        self.assertEquals(expected, data)
def remove_instance_fw_rule_set(instance_id, set_id):
    server = fetch_instance(instance_id)
    sg = _find_sg_on_server(instance_id, set_id)
    tcs = client_set_for_tenant(server.tenant_id, fallback_to_api=g.is_admin)

    try:
        tcs.compute.servers.remove_security_group(server, sg.name)
    except osc_exc.BadRequest, e:
        raise exc.InvalidRequest(str(e))
Exemple #36
0
def remove_instance_fw_rule_set(instance_id, set_id):
    server = fetch_instance(instance_id)
    sg = _find_sg_on_server(instance_id, set_id)
    tcs = client_set_for_tenant(server.tenant_id, fallback_to_api=g.is_admin)

    try:
        tcs.compute.servers.remove_security_group(server, sg.name)
    except osc_exc.BadRequest, e:
        raise exc.InvalidRequest(str(e))
Exemple #37
0
    def test_vnc_works(self):
        s = self.server
        expected = {
            'instance': {
                'id': s.id,
                'name': s.name,
                'href': '/v1/instances/%s' % s.id
            },
            'url': 'CONSOLE URL',
            'console-type': 'novnc'
        }
        console = {'url': 'CONSOLE URL', 'type': 'novnc'}

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_vnc_console(console_type='novnc')\
                .AndReturn({'console': console})

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/vnc' % s.id, {})
        self.assertEquals(expected, data)
    def test_vnc_works(self):
        s = self.server
        expected = {
            'instance': {
                'id': s.id,
                'name': s.name,
                'href': '/v1/instances/%s' % s.id
            },
            'url': 'CONSOLE URL',
            'console-type': 'novnc'
        }
        console = {
            'url': 'CONSOLE URL',
            'type': 'novnc'
        }

        instances.fetch_instance(s.id).AndReturn(s)
        s.get_vnc_console(console_type='novnc')\
                .AndReturn({'console': console})

        self.mox.ReplayAll()
        data = self.interact('/v1/instances/%s/vnc' % s.id, {})
        self.assertEquals(expected, data)
def add_instance_fw_rule_set(instance_id):
    server = fetch_instance(instance_id)
    set_id = parse_request_data(required=_SCHEMA.required)['id']
    set_audit_resource_id(set_id)
    try:
        sg = admin_client_set().compute.security_groups.get(set_id)
    except osc_exc.NotFound:
        raise exc.InvalidElementValue('id', 'string', set_id,
                                      'Security group does not exist')

    tcs = client_set_for_tenant(server.tenant_id, fallback_to_api=g.is_admin)
    try:
        tcs.compute.servers.add_security_group(server, sg.name)
    except osc_exc.BadRequest, e:
        raise exc.InvalidRequest(str(e))
Exemple #40
0
def add_instance_fw_rule_set(instance_id):
    server = fetch_instance(instance_id)
    set_id = parse_request_data(required=_SCHEMA.required)['id']
    set_audit_resource_id(set_id)
    try:
        sg = admin_client_set().compute.security_groups.get(set_id)
    except osc_exc.NotFound:
        raise exc.InvalidElementValue('id', 'string', set_id,
                                      'Security group does not exist')

    tcs = client_set_for_tenant(server.tenant_id, fallback_to_api=g.is_admin)
    try:
        tcs.compute.servers.add_security_group(server, sg.name)
    except osc_exc.BadRequest, e:
        raise exc.InvalidRequest(str(e))
    def test_fetch_instance_as_user(self):
        self.mox.StubOutWithMock(instances, 'admin_client_set')
        self.mox.StubOutWithMock(instances, 'assert_admin_or_project_user')
        instance = doubles.make(self.mox, doubles.Server,
                          id='VMID', tenant_id='PID', name='test')

        tcs = self._fake_client_set_factory()
        instances.admin_client_set().AndReturn(tcs)
        tcs.compute.servers.get('VMID').AndReturn(instance)
        instances.assert_admin_or_project_user('PID', eperm_status=404)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.install_fake_auth()
            result = instances.fetch_instance('VMID')
        self.assertEquals(result, instance)
Exemple #42
0
    def test_fetch_instance_as_user(self):
        self.mox.StubOutWithMock(instances, 'admin_client_set')
        self.mox.StubOutWithMock(instances, 'assert_admin_or_project_user')
        instance = doubles.make(self.mox,
                                doubles.Server,
                                id='VMID',
                                tenant_id='PID',
                                name='test')

        tcs = self._fake_client_set_factory()
        instances.admin_client_set().AndReturn(tcs)
        tcs.compute.servers.get('VMID').AndReturn(instance)
        instances.assert_admin_or_project_user('PID', eperm_status=404)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.install_fake_auth()
            result = instances.fetch_instance('VMID')
        self.assertEquals(result, instance)