~ibmcharmers/charms/trusty/ibm-glance-spectrumscale/trunk

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
#
# Copyright 2016 Canonical Ltd
#
# 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.

"""
Basic glance-spectrumscale functional test.
"""
# import amulet
# import json
# import time
import yaml
import os

from charmhelpers.contrib.openstack.amulet.deployment import (
    OpenStackAmuletDeployment
)


seconds_to_wait = 2000


class GlanceSpectrumscaleBasicDeployment(OpenStackAmuletDeployment):
    """Amulet tests on a basic heat deployment."""
    def __init__(self, series=None, openstack=None, source=None, git=False,
                 stable=True):
        """Deploy the entire test environment."""
        super(GlanceSpectrumscaleBasicDeployment, self).__init__(series,
                                                                 openstack,
                                                                 source,
                                                                 stable)
        self.git = git
        self._add_services()
        self._add_relations()
        self._configure_services()
        self._deploy()

        exclude_services = []

        # Wait for deployment ready msgs, except exclusions
        self._auto_wait_for_status(exclude_services=exclude_services)
        self._check_glancedriver()
        self.d.sentry.wait(seconds_to_wait)

    def _add_services(self):
        """Add the services that we're testing, where cinder-ceph is
        local, and the rest of the services are from lp branches that
        are compatible with the local charm (e.g. stable or next).
        """
        # Note: cinder-ceph becomes a cinder subordinate unit.
        this_service = {'name': 'ibm-glance-spectrumscale'}
        other_services = [
            {'name': 'percona-cluster', 'constraints': {'mem': '3072M'}},
            {'name': 'keystone'},
            {'name': 'rabbitmq-server'},
            {'name': 'glance'},
            {'name': 'ubuntu'},
            {'name': 'ibm-spectrum-scale-client', 'location': 'cs:~ibmcharmers/ \
             xenial/ibm-spectrum-scale-client-4'},
            {'name': 'ibm-spectrum-scale-manager', 'location': 'cs:~ibmcharmers/ \
             ibm-spectrum-scale-manager-5', 'units': 2},
        ]
        super(GlanceSpectrumscaleBasicDeployment, self)._add_services(
            this_service, other_services)

    def _add_relations(self):
        """Add all of the relations for the services."""

        relations = {
            'glance:storage-backend':
                'ibm-glance-spectrumscale:storage-backend',
            'glance:identity-service': 'keystone:identity-service',
            'glance:shared-db': 'percona-cluster:shared-db',
            'keystone:shared-db': 'percona-cluster:shared-db',
            'glance:amqp': 'rabbitmq-server:amqp',
            'ubuntu:juju-info': 'ibm-spectrum-scale-client:juju-info',
            'ibm-spectrum-scale-manager:gpfsmanager':
                'ibm-spectrum-scale-client:gpfsmanager',
            'ibm-spectrum-scale-client:client':
                'ibm-glance-spectrumscale:spectrumscale'
        }
        super(GlanceSpectrumscaleBasicDeployment, self)._add_relations(
            relations)

    def _configure_services(self):
        """Configure all of the services."""
        glance_config = {}
        if self.git:
            amulet_http_proxy = os.environ.get('AMULET_HTTP_PROXY')

            reqs_repo = 'git://github.com/openstack/requirements'
            glance_repo = 'git://github.com/openstack/glance'
            if self._get_openstack_release() == self.trusty_icehouse:
                reqs_repo = 'git://github.com/coreycb/requirements'
                glance_repo = 'git://github.com/coreycb/glance'

            branch = 'stable/' + self._get_openstack_release_string()

            openstack_origin_git = {
                'repositories': [
                    {'name': 'requirements',
                     'repository': reqs_repo,
                     'branch': branch},
                    {'name': 'glance',
                     'repository': glance_repo,
                     'branch': branch},
                ],
                'directory': '/mnt/openstack-git',
                'http_proxy': amulet_http_proxy,
                'https_proxy': amulet_http_proxy,
            }
            glance_config['openstack-origin-git'] = \
                yaml.dump(openstack_origin_git)

        keystone_config = {
            'admin-password': 'openstack',
            'admin-token': 'ubuntutesting'
        }
        pxc_config = {
            'dataset-size': '25%',
            'max-connections': 1000,
            'root-password': 'ChangeMe123',
            'sst-password': 'ChangeMe123',
        }
        configs = {
            'keystone': keystone_config,
            'percona-cluster': pxc_config,
            'glance': glance_config,
            # 'ibm-cinder-spectrumscale': cinder_spectrumscale_config,
        }
        super(GlanceSpectrumscaleBasicDeployment, self)._configure_services(
            configs)

    def _check_glancedriver(self):
        unit = self.d.sentry['ibm-glance-spectrumscale'][0]
        hostname, code = unit.run('hostname')
        unit_client = self.d.sentry['ibm-spectrum-scale-client'][0]
        host_name, code = unit_client.run("grep %s /etc/hosts | cut -d' ' -f2"
                                          % hostname)

        # To check whether host name of driver is added to /etc/hosts file of
        # client. This is to test the interface between driver and client
        if str(host_name) == str(hostname):
            self.log.debug('Host name in client /etc/hosts file ... OK')
        else:
            self.log.debug('Host name in client /etc/hosts file ... Failed')