~xtoddx/nova/provider-fw-rules

« back to all changes in this revision

Viewing changes to nova/tests/test_adminapi.py

  • Committer: Todd Willey
  • Date: 2011-06-23 17:54:45 UTC
  • Revision ID: todd@ansolabs.com-20110623175445-dlf7w2es5vdmqft6
Add admin api test case (like cloud test case) with a test for fw rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 United States Government as represented by the
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
#    not use this file except in compliance with the License. You may obtain
 
9
#    a copy of the License at
 
10
#
 
11
#         http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
#    License for the specific language governing permissions and limitations
 
17
#    under the License.
 
18
 
 
19
from eventlet import greenthread
 
20
 
 
21
from nova import context
 
22
from nova import db
 
23
from nova import flags
 
24
from nova import log as logging
 
25
from nova import rpc
 
26
from nova import test
 
27
from nova import utils
 
28
from nova.auth import manager
 
29
from nova.api.ec2 import admin
 
30
from nova.image import fake
 
31
 
 
32
 
 
33
FLAGS = flags.FLAGS
 
34
LOG = logging.getLogger('nova.tests.adminapi')
 
35
 
 
36
 
 
37
class AdminApiTestCase(test.TestCase):
 
38
    def setUp(self):
 
39
        super(AdminApiTestCase, self).setUp()
 
40
        self.flags(connection_type='fake')
 
41
 
 
42
        self.conn = rpc.Connection.instance()
 
43
 
 
44
        # set up our cloud
 
45
        self.api = admin.AdminController()
 
46
 
 
47
        # set up services
 
48
        self.compute = self.start_service('compute')
 
49
        self.scheduter = self.start_service('scheduler')
 
50
        self.network = self.start_service('network')
 
51
        self.volume = self.start_service('volume')
 
52
        self.image_service = utils.import_object(FLAGS.image_service)
 
53
 
 
54
        self.manager = manager.AuthManager()
 
55
        self.user = self.manager.create_user('admin', 'admin', 'admin', True)
 
56
        self.project = self.manager.create_project('proj', 'admin', 'proj')
 
57
        self.context = context.RequestContext(user=self.user,
 
58
                                              project=self.project)
 
59
        host = self.network.get_network_host(self.context.elevated())
 
60
 
 
61
        def fake_show(meh, context, id):
 
62
            return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
 
63
                    'type': 'machine', 'image_state': 'available'}}
 
64
 
 
65
        self.stubs.Set(fake._FakeImageService, 'show', fake_show)
 
66
        self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show)
 
67
 
 
68
        # NOTE(vish): set up a manual wait so rpc.cast has a chance to finish
 
69
        rpc_cast = rpc.cast
 
70
 
 
71
        def finish_cast(*args, **kwargs):
 
72
            rpc_cast(*args, **kwargs)
 
73
            greenthread.sleep(0.2)
 
74
 
 
75
        self.stubs.Set(rpc, 'cast', finish_cast)
 
76
 
 
77
    def tearDown(self):
 
78
        network_ref = db.project_get_network(self.context,
 
79
                                             self.project.id)
 
80
        db.network_disassociate(self.context, network_ref['id'])
 
81
        self.manager.delete_project(self.project)
 
82
        self.manager.delete_user(self.user)
 
83
        super(AdminApiTestCase, self).tearDown()
 
84
 
 
85
    def test_block_external_ips(self):
 
86
        """Make sure provider firewall rules are created."""
 
87
        result = self.api.block_external_addresses(self.context, '1.1.1.1/32')
 
88
        self.assertEqual('OK', result['status'])
 
89
        self.assertEqual('Added 3 rules', result['message'])
 
90