~simpoir/landscape-client-charm/charm_push_target

« back to all changes in this revision

Viewing changes to hooks/test_hooks.py

  • Committer: 🤖 Landscape Builder
  • Author(s): Adam Collard
  • Date: 2019-04-05 14:05:56 UTC
  • mfrom: (67.1.4 install_sources_keys)
  • Revision ID: _landscape_builder-20190405140556-02pk7xjksbmwjtrm
Add install_sources and install_keys support to landscape-client charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from base64 import b64encode
1
2
import json
2
3
import socket
3
4
import os
7
8
from uuid import uuid4
8
9
 
9
10
import six
10
 
from landscape.deployment import Configuration
 
11
from systemfixtures import FakeProcesses
 
12
try:
 
13
    from landscape.client.deployment import Configuration
 
14
except ImportError:
 
15
    from landscape.deployment import Configuration
11
16
from landscape.lib.fs import read_file
 
17
 
12
18
import hooks
 
19
 
13
20
from common import LandscapeBroker, JujuBroker, write_json_file
14
21
from stubs import FetchStub, HookenvStub
15
22
 
72
79
        os.environ["CHARM_DIR"] = self.charm_dir
73
80
        self.hookenv = HookenvStub(self.charm_dir)
74
81
        self.fetch = FetchStub(needs_update=True)
 
82
        self.processes = FakeProcesses()
 
83
        self.processes.setUp()
75
84
 
76
85
        def status_set(workload_state, message):
77
86
            self.workload_state = workload_state
91
100
    def config(self):
92
101
        """Return the base application config."""
93
102
        config = self.hookenv.config()
94
 
        config.update({"origin": "distro"})
 
103
        config.update({"install-sources": '["distro"]'})
95
104
        return config
96
105
 
97
106
 
428
437
 
429
438
    def setUp(self):
430
439
        super(ConfigChangedTest, self).setUp()
 
440
 
 
441
        def landscape_config(proc_args):
 
442
            return {"stdout": six.moves.cStringIO("")}
 
443
        self.processes.add(landscape_config, name="landscape-config")
431
444
        self.landscape_broker.config.account_name = "account1"
432
445
        self.landscape_broker.config.computer_title = "title"
433
446
        self.addCleanup(setattr, hooks, "CERT_FILE", hooks.CERT_FILE)
441
454
        self.touch_juju_info_file()
442
455
        config = self.config()
443
456
        config.update({
444
 
            "ssl-public-key": "base64:%s" % "foo".encode("base64"),
 
457
            "ssl-public-key": "base64:%s" % b64encode(b"foo").decode('utf-8'),
445
458
            "account-name": "standalone",
446
459
            "ping-url": "http://127.0.0.1"})
447
460
 
462
475
        self.touch_juju_info_file()
463
476
        config = self.config()
464
477
        config.update({
465
 
            "ssl-public-key": "base64:%s" % "foo".encode("base64"),
 
478
            "ssl-public-key": "base64:%s" % b64encode(b"foo").decode('utf-8'),
466
479
            "account-name": "",
467
480
            "ping-url": "http://127.0.0.1"})
468
481
 
480
493
        """
481
494
        config = self.config()
482
495
        config.update({
483
 
            "ssl-public-key": "base64:%s" % "foo".encode("base64"),
 
496
            "ssl-public-key": "base64:%s" % b64encode(b"foo").decode('utf-8'),
484
497
            "account-name": "standalone",
485
498
            "ping-url": "http://127.0.0.1"})
486
499
 
495
508
        """Leading and trailing whitespace is removed from config settings"""
496
509
        config = self.config()
497
510
        config.update({
498
 
            "ssl-public-key": " base64:%s" % "foo".encode("base64"),
 
511
            "ssl-public-key": " base64:%s" % b64encode(b"foo").decode('utf-8'),
499
512
            "account-name": " standalone\t",
500
513
            "registration-key": " mykey\n",
501
514
            "ping-url": " \thttp://127.0.0.1\n "})
598
611
        A base64 encoded SSL cert in the registration relation is decoded.
599
612
        """
600
613
        self.juju_broker.commands["relation-get"] = {
601
 
            "ssl-public-key": "base64:%s" % "foo".encode("base64"),
 
614
            "ssl-public-key": "base64:%s" % b64encode(b"foo").decode('utf-8'),
602
615
            "account-name": "standalone",
603
616
            "ping-url": "http://127.0.0.1/ping"}
604
617
        hooks.registration_relation(juju_broker=self.juju_broker,