File: test_cli_deployment.py

package info (click to toggle)
rally-openstack 3.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,928 kB
  • sloc: python: 53,131; sh: 262; makefile: 38
file content (123 lines) | stat: -rw-r--r-- 5,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
import json
import re
import unittest

from tests.functional import utils


TEST_ENV = {
    "OS_USERNAME": "admin",
    "OS_PASSWORD": "admin",
    "OS_TENANT_NAME": "admin",
    "OS_AUTH_URL": "http://fake/",
}


class DeploymentTestCase(unittest.TestCase):

    def test_create_fromenv_list_show(self):
        # NOTE(andreykurilin): `rally deployment create --fromenv` is
        #   hardcoded to OpenStack. Should be fixed as soon as the platforms
        #   will be introduced.
        rally = utils.Rally()
        rally.env.update(TEST_ENV)

        rally("deployment create --name t_create_env --fromenv")
        self.assertIn("t_create_env", rally("deployment list"))
        self.assertIn(TEST_ENV["OS_AUTH_URL"],
                      rally("deployment show"))

    def test_create_fromfile(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        rally("deployment create --name t_create_env --fromenv")
        existing_conf = rally("deployment config", getjson=True)
        with open("/tmp/.tmp.deployment", "w") as f:
            f.write(json.dumps(existing_conf))
        rally("deployment create --name t_create_file "
              "--filename /tmp/.tmp.deployment")
        self.assertIn("t_create_file", rally("deployment list"))

    def test_destroy(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        rally("deployment create --name t_create_env --fromenv")
        self.assertIn("t_create_env", rally("deployment list"))
        rally("deployment destroy")
        self.assertNotIn("t_create_env", rally("deployment list"))

    def test_check_success(self):
        rally = utils.Rally()
        rally("deployment check")

    def test_check_fail(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        rally("deployment create --name t_create_env --fromenv")
        self.assertRaises(utils.RallyCliError, rally, "deployment check")

    def test_check_debug(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        rally("deployment create --name t_create_env --fromenv")
        config = rally("deployment config", getjson=True)
        config["openstack"]["admin"]["password"] = "fakepassword"
        file = utils.JsonTempFile(config)
        rally("deployment create --name t_create_file_debug "
              "--filename %s" % file.filename)
        self.assertIn("t_create_file_debug", rally("deployment list"))
        self.assertEqual(config, rally("deployment config", getjson=True))
        with self.assertRaises(utils.RallyCliError) as e_ctx:
            rally("--debug deployment check")
        self.assertIn(
            "AuthenticationFailed: Could not find versioned identity "
            "endpoints when attempting to authenticate.",
            e_ctx.exception.output)

    def test_use(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        output = rally(
            "deployment create --name t_create_env1 --fromenv")
        uuid = re.search(r"Using deployment: (?P<uuid>[0-9a-f\-]{36})",
                         output).group("uuid")
        rally("deployment create --name t_create_env2 --fromenv")
        rally("deployment use --deployment %s" % uuid)
        current_deployment = utils.get_global("RALLY_DEPLOYMENT",
                                              rally.env)
        self.assertEqual(uuid, current_deployment)

    def test_create_from_env_openstack_deployment(self):
        rally = utils.Rally()
        rally.env.update(TEST_ENV)
        rally("deployment create --name t_create_env --fromenv")
        config = rally("deployment config", getjson=True)
        self.assertIn("openstack", config)
        self.assertEqual(TEST_ENV["OS_USERNAME"],
                         config["openstack"]["admin"]["username"])
        self.assertEqual(TEST_ENV["OS_PASSWORD"],
                         config["openstack"]["admin"]["password"])
        if "project_name" in config["openstack"]["admin"]:
            # keystone v3
            self.assertEqual(TEST_ENV["OS_TENANT_NAME"],
                             config["openstack"]["admin"]["project_name"])
        else:
            # keystone v2
            self.assertEqual(TEST_ENV["OS_TENANT_NAME"],
                             config["openstack"]["admin"]["tenant_name"])
        self.assertEqual(TEST_ENV["OS_AUTH_URL"],
                         config["openstack"]["auth_url"])