~1chb1n/charms/trusty/ceilometer/next.1601-test-update1

« back to all changes in this revision

Viewing changes to tests/basic_deployment.py

Merge lp:~tealeg/charms/trusty/ceilometer/pause-and-resume [a=tealeg] [r=tribaal, ack]

Add pause and resume actions for the ceilometer services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
import subprocess
 
4
 
3
5
"""
4
6
Basic ceilometer functional tests.
5
7
"""
6
8
import amulet
 
9
import json
7
10
import time
8
11
from ceilometerclient.v2 import client as ceilclient
9
12
 
107
110
                                                   endpoint_type='publicURL')
108
111
        self.ceil = ceilclient.Client(endpoint=ep, token=self._get_token)
109
112
 
 
113
    def _run_action(self, unit_id, action, *args):
 
114
        command = ["juju", "action", "do", "--format=json", unit_id, action]
 
115
        command.extend(args)
 
116
        print("Running command: %s\n" % " ".join(command))
 
117
        output = subprocess.check_output(command)
 
118
        output_json = output.decode(encoding="UTF-8")
 
119
        data = json.loads(output_json)
 
120
        action_id = data[u'Action queued with id']
 
121
        return action_id
 
122
 
 
123
    def _wait_on_action(self, action_id):
 
124
        command = ["juju", "action", "fetch", "--format=json", action_id]
 
125
        while True:
 
126
            try:
 
127
                output = subprocess.check_output(command)
 
128
            except Exception as e:
 
129
                print(e)
 
130
                return False
 
131
            output_json = output.decode(encoding="UTF-8")
 
132
            data = json.loads(output_json)
 
133
            if data[u"status"] == "completed":
 
134
                return True
 
135
            elif data[u"status"] == "failed":
 
136
                return False
 
137
            time.sleep(2)
 
138
 
110
139
    def test_100_services(self):
111
140
        """Verify the expected services are running on the corresponding
112
141
           service units."""
569
598
            sleep_time = 0
570
599
 
571
600
        self.d.configure(juju_service, set_default)
 
601
 
 
602
    def test_1000_pause_and_resume(self):
 
603
        """The services can be paused and resumed. """
 
604
        unit_name = "ceilometer/0"
 
605
        unit = self.d.sentry.unit[unit_name]
 
606
 
 
607
        assert u.status_get(unit)[0] == "unknown"
 
608
 
 
609
        action_id = self._run_action(unit_name, "pause")
 
610
        assert self._wait_on_action(action_id), "Pause action failed."
 
611
        assert u.status_get(unit)[0] == "maintenance"
 
612
 
 
613
        action_id = self._run_action(unit_name, "resume")
 
614
        assert self._wait_on_action(action_id), "Resume action failed."
 
615
        assert u.status_get(unit)[0] == "active"