blob: bd937d54fff1e1c301230b0d92d24adc45f7d6c5 [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# Copyright 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tcp_tests import logger
16from tcp_tests import settings
17
18
19LOG = logger.logger
20
21
22class RallyManager(object):
23 """docstring for RallyManager"""
24
25 image_name = 'rallyforge/rally'
26 image_version = '0.5.0'
27
28 def __init__(self, underlay, admin_node_name):
29 super(RallyManager, self).__init__()
30 self._admin_node_name = admin_node_name
31 self._underlay = underlay
32
33 def prepare(self):
34 content = """
35sed -i 's|#swift_operator_role = Member|swift_operator_role=SwiftOperator|g' /etc/rally/rally.conf # noqa
36source /home/rally/openrc
37rally-manage db recreate
38rally deployment create --fromenv --name=tempest
39rally verify install
40rally verify genconfig
41rally verify showconfig"""
42 cmd = "cat > {path} << EOF\n{content}\nEOF".format(
43 path='/home/{user}/rally/install_tempest.sh'.format(
44 user=settings.SSH_LOGIN), content=content)
45 cmd1 = "chmod +x /home/{user}/rally/install_tempest.sh".format(
46 user=settings.SSH_LOGIN)
47 cmd2 = "cp /home/{user}/openrc-* /home/{user}/rally/openrc".format(
48 user=settings.SSH_LOGIN)
49
50 with self._underlay.remote(node_name=self._admin_node_name) as remote:
51 LOG.info("Create rally workdir")
52 remote.check_call('mkdir -p /home/{user}/rally'.format(
53 user=settings.SSH_LOGIN))
54 LOG.info("Create install_tempest.sh")
55 remote.check_call(cmd)
56 LOG.info("Chmod +x install_tempest.sh")
57 remote.check_call(cmd1)
58 LOG.info("Copy openstackrc")
59 remote.check_call(cmd2)
60
61 def pull_image(self, version=None):
62 version = version or self.image_version
63 image = self.image_name
64 cmd = "docker pull {image}:{version}".format(image=image,
65 version=version)
66 with self._underlay.remote(node_name=self._admin_node_name) as remote:
67 LOG.info("Pull {image}:{version}".format(image=image,
68 version=version))
69 remote.check_call(cmd)
70
71 with self._underlay.remote(node_name=self._admin_node_name) as remote:
72 LOG.info("Getting image id")
73 cmd = "docker images | grep 0.5.0| awk '{print $3}'"
74 res = remote.check_call(cmd)
75 self.image_id = res['stdout'][0].strip()
76 LOG.info("Image ID is {}".format(self.image_id))
77
78 def run(self):
79 with self._underlay.remote(node_name=self._admin_node_name) as remote:
80 cmd = ("docker run --net host -v /home/{user}/rally:/home/rally "
81 "-tid -u root {image_id}".format(
82 user=settings.SSH_LOGIN, image_id=self.image_id))
83 LOG.info("Run Rally container")
84 remote.check_call(cmd)
85
86 cmd = ("docker ps | grep {image_id} | "
87 "awk '{{print $1}}'| head -1").format(
88 image_id=self.image_id)
89 LOG.info("Getting container id")
90 res = remote.check_call(cmd)
91 self.docker_id = res['stdout'][0].strip()
92 LOG.info("Container ID is {}".format(self.docker_id))
93
94 def run_tempest(self, test=''):
95 docker_exec = ('source /home/{user}/rally/openrc; '
96 'docker exec -i {docker_id} bash -c "{cmd}"')
97 commands = [
98 docker_exec.format(cmd="./install_tempest.sh",
99 user=settings.SSH_LOGIN,
100 docker_id=self.docker_id),
101 docker_exec.format(
102 cmd="source /home/rally/openrc && "
103 "rally verify start {test}".format(test=test),
104 user=settings.SSH_LOGIN,
105 docker_id=self.docker_id),
106 docker_exec.format(
107 cmd="rally verify results --json --output-file result.json",
108 user=settings.SSH_LOGIN,
109 docker_id=self.docker_id),
110 docker_exec.format(
111 cmd="rally verify results --html --output-file result.html",
112 user=settings.SSH_LOGIN,
113 docker_id=self.docker_id),
114 ]
115 with self._underlay.remote(node_name=self._admin_node_name) as remote:
116 LOG.info("Run tempest inside Rally container")
117 for cmd in commands:
118 remote.check_call(cmd, verbose=True)