~chad.smith/landscape-charm/maas-haproxy-smoosh

« back to all changes in this revision

Viewing changes to tests/helpers.py

  • Committer: Landscape Builder
  • Author(s): Danilo Šegan
  • Date: 2015-06-15 09:27:05 UTC
  • mfrom: (306.1.11 admin-user-action)
  • Revision ID: landscape_builder-20150615092705-vouyiaxg1czmkzui
Merge admin-user-action [f=1462387] [r=landscape-builder,free.ekanayaka,benji] [a=Данило Шеган]
Create bootstrap action that creates an LDS account and adds an admin user

Introduce "bootstrap" action that takes "admin-name", "admin-email" and "admin-password" parameters and creates a "standalone" LDS account with the appropriate admin user.

At the moment, we are using 'schema --create-lds-account-only', though we should move to not using this in the future.  This script doesn't report nicely if you've already called 'bootstrap' once.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import json
13
13
import time
14
14
 
 
15
from operator import itemgetter
15
16
from os import getenv
16
17
from time import sleep
17
18
from configparser import ConfigParser
211
212
        action_id = self._do_action("resume", unit.info["unit_name"])
212
213
        return self._fetch_action(action_id)
213
214
 
 
215
    def bootstrap_landscape(self, admin_name, admin_email, admin_password,
 
216
                            unit=None):
 
217
        """Execute the 'bootstrap' action on a Landscape unit.
 
218
 
 
219
        The results of the action is returned.
 
220
        """
 
221
        unit = self._get_service_unit("landscape-server", unit=unit)
 
222
        bootstrap_params = {"admin-name": admin_name,
 
223
                            "admin-email": admin_email,
 
224
                            "admin-password": admin_password}
 
225
        action_id = self._do_action(
 
226
            "bootstrap", unit.info["unit_name"], bootstrap_params)
 
227
        return self._fetch_action(action_id)
 
228
 
214
229
    def wait_landscape_cron_jobs(self, unit=None):
215
230
        """Wait for running cron jobs to finish on the given Landscape unit."""
216
231
        unit = self._get_service_unit("landscape-server", unit=unit)
355
370
        stdout, stderr = process.communicate()
356
371
        return stdout.decode("utf-8"), stderr.decode("utf-8")
357
372
 
358
 
    def _do_action(self, action, unit):
 
373
    def _do_action(self, action, unit, action_params=None):
359
374
        """Execute an action on a unit, returning the id."""
360
 
        result = json.loads(subprocess.check_output(
361
 
            ["juju", "action", "do", "--format=json",
362
 
             unit, action]).decode("utf-8"))
 
375
        command = ["juju", "action", "do", "--format=json", unit, action]
 
376
        if action_params is not None:
 
377
            sorted_action_params = sorted(
 
378
                action_params.items(), key=itemgetter(0))
 
379
            for key, value in sorted_action_params:
 
380
                if value is not None:
 
381
                    command.append("%s=%s" % (key, value))
 
382
        result = json.loads(
 
383
            self._subprocess.check_output(command).decode("utf-8"))
363
384
        return result["Action queued with id"]
364
385
 
365
386
    def _fetch_action(self, action_id, wait=300):
366
387
        """Fetch the results of an action."""
367
 
        return json.loads(subprocess.check_output(
 
388
        return json.loads(self._subprocess.check_output(
368
389
            ["juju", "action", "fetch", "--format=json", "--wait", str(wait),
369
390
             action_id]).decode("utf-8"))
370
391