~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to smoketests/admin_smoketests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-12-13 10:17:01 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101213101701-txhhqbzsxw4avnxv
Tags: upstream-2011.1~bzr456
ImportĀ upstreamĀ versionĀ 2011.1~bzr456

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
import os
 
20
import random
 
21
import sys
 
22
import time
 
23
import unittest
 
24
import zipfile
 
25
 
 
26
from nova import adminclient
 
27
from smoketests import flags
 
28
from smoketests import base
 
29
 
 
30
 
 
31
SUITE_NAMES = '[user]'
 
32
 
 
33
FLAGS = flags.FLAGS
 
34
flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES)
 
35
 
 
36
# TODO(devamcar): Use random tempfile
 
37
ZIP_FILENAME = '/tmp/nova-me-x509.zip'
 
38
 
 
39
TEST_PREFIX = 'test%s' % int(random.random()*1000000)
 
40
TEST_USERNAME = '%suser' % TEST_PREFIX
 
41
TEST_PROJECTNAME = '%sproject' % TEST_PREFIX
 
42
 
 
43
 
 
44
class AdminSmokeTestCase(base.SmokeTestCase):
 
45
    def setUp(self):
 
46
        self.admin = adminclient.NovaAdminClient(
 
47
            access_key=os.getenv('EC2_ACCESS_KEY'),
 
48
            secret_key=os.getenv('EC2_SECRET_KEY'),
 
49
            clc_url=os.getenv('EC2_URL'),
 
50
            region=FLAGS.region)
 
51
 
 
52
 
 
53
class UserTests(AdminSmokeTestCase):
 
54
    """ Test admin credentials and user creation. """
 
55
 
 
56
    def test_001_admin_can_connect(self):
 
57
        conn = self.admin.connection_for('admin', 'admin')
 
58
        self.assert_(conn)
 
59
 
 
60
    def test_002_admin_can_create_user(self):
 
61
        user = self.admin.create_user(TEST_USERNAME)
 
62
        self.assertEqual(user.username, TEST_USERNAME)
 
63
 
 
64
    def test_003_admin_can_create_project(self):
 
65
        project = self.admin.create_project(TEST_PROJECTNAME,
 
66
                                            TEST_USERNAME)
 
67
        self.assertEqual(project.projectname, TEST_PROJECTNAME)
 
68
 
 
69
    def test_004_user_can_download_credentials(self):
 
70
        buf = self.admin.get_zip(TEST_USERNAME, TEST_PROJECTNAME)
 
71
        output = open(ZIP_FILENAME, 'w')
 
72
        output.write(buf)
 
73
        output.close()
 
74
 
 
75
        zip = zipfile.ZipFile(ZIP_FILENAME, 'a', zipfile.ZIP_DEFLATED)
 
76
        bad = zip.testzip()
 
77
        zip.close()
 
78
 
 
79
        self.failIf(bad)
 
80
 
 
81
    def test_999_tearDown(self):
 
82
        self.admin.delete_project(TEST_PROJECTNAME)
 
83
        self.admin.delete_user(TEST_USERNAME)
 
84
        try:
 
85
            os.remove(ZIP_FILENAME)
 
86
        except:
 
87
            pass
 
88
 
 
89
if __name__ == "__main__":
 
90
    suites = {'user': unittest.makeSuite(UserTests)}
 
91
    sys.exit(base.run_tests(suites))
 
92