Example #1
0
 def test_relate_before_service_deployed(self):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     with self.assertRaises(ValueError) as e:
         d.relate('mysql:db', 'wordpress:db')
         self.assertEqual(
             'Can not relate, service not deployed yet', str(e))
Example #2
0
 def test_add_units(self):
     d = Deployment(juju_env='gojuju')
     d.add('charm', units=2)
     self.assertEqual({'charm': {
         'branch': 'lp:charms/charm',
         'units': 2
     }}, d.services)
Example #3
0
 def test_build_sentries_writes_relationship_sentry_metadata(self):
     """Even if there are no relations the metadata.yaml is written."""
     d = Deployment(juju_env='gojuju', sentries=True)
     d.build_sentries()
     self.assertIn('metadata.yaml',
                   os.listdir(d.relationship_sentry.charm))
     d.cleanup()
Example #4
0
    def test_relate_relation_nonexist(self, mcharm):
        d = Deployment(juju_env='gojuju')
        d.add('bar')
        d.add('foo')

        self.assertRaises(ValueError, d.relate, 'foo:f', 'bar:b')
        d.cleanup()
Example #5
0
 def test_relate_before_service_deployed(self):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     with self.assertRaises(ValueError) as e:
         d.relate('mysql:db', 'wordpress:db')
         self.assertEqual('Can not relate, service not deployed yet',
                          str(e))
Example #6
0
    def test_add_unit_error(self, mcharm, subprocess, waiter_status,
                            environments, upload_scripts):
        def mock_unit_error(f, service, unit_name):
            def _mock_unit_error(juju_env):
                status = f(juju_env)
                unit = status['services'][service]['units'].get(unit_name)
                if not unit:
                    return status
                unit['agent-state'] = 'error'
                unit['agent-state-info'] = 'hook failed: install'
                return status
            return _mock_unit_error

        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None
        charm.series = 'precise'

        environments.return_value = yaml.safe_load(RAW_ENVIRONMENTS_YAML)

        d = Deployment(juju_env='gojuju')
        waiter_status.side_effect = mock_unit_error(
            self._make_mock_status(d), 'charm', 'charm/1')
        d.add('charm', units=1)
        d.setup()
        with patch('amulet.deployer.juju'):
            self.assertRaisesRegexp(
                Exception, 'Error on unit charm/1: hook failed: install',
                d.add_unit, 'charm')
Example #7
0
 def test_unrelate_bad_service_format(self):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     with self.assertRaises(ValueError) as e:
         d.unrelate('mysql', 'wordpress')
         self.assertEqual(
             str(e), 'All relations must be explicit, service:relation')
Example #8
0
 def test_load(self):
     d = Deployment(juju_env='gojuju')
     schema = '{"mybundle": {"series": "raring", "services": {"wordpress": \
               {"branch": "lp:~charmers/charms/precise/wordpress/trunk"}, \
               "mysql": {"options": {"tuning": "fastest"}, \
               "constraints": "mem=2G cpu-cores=2", \
               "branch": "lp:~charmers/charms/precise/mysql/trunk"}}, \
               "relations": [["mysql:db", "wordpress:db"]]}}'
     dmap = json.loads(schema)
     with patch.object(d, 'add') as add:
         with patch.object(d, 'configure') as configure:
             d.load(dmap)
     self.assertEqual(d.juju_env, 'gojuju')
     self.assertEqual(dmap['mybundle']['relations'], d.relations)
     self.assertEqual(dmap['mybundle']['series'], d.series)
     add.assert_has_calls([
         call('wordpress',
              placement=None,
              series='raring',
              units=1,
              branch='lp:~charmers/charms/precise/wordpress/trunk',
              constraints=None,
              charm=None),
         call('mysql',
              placement=None,
              series='raring',
              units=1,
              branch='lp:~charmers/charms/precise/mysql/trunk',
              constraints={'mem': '2G', 'cpu-cores': '2'},
              charm=None)],
         any_order=True
     )
     configure.assert_has_calls([
         call('mysql', {'tuning': 'fastest'}),
     ])
Example #9
0
 def test_add_branch(self):
     d = Deployment(juju_env='gojuju')
     d.add('bar', 'cs:~foo/bar')
     self.assertEqual(
         {'bar': {
             'branch': 'lp:~foo/charms/precise/bar/trunk'
         }}, d.services)
Example #10
0
 def test_action_defined(self, mj):
     mj.return_value = '{"action": "description"}'
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     actions = d.action_defined('mysql')
     self.assertEquals(actions, {"action": "description"})
     mj.assert_has_calls([call(['action', 'defined', 'mysql', '--format', 'json'])])
Example #11
0
 def test_action_do(self, mj):
     mj.return_value = '{"Action queued with id": "some-action-id"}'
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json'])])
Example #12
0
 def test_unrelate_bad_service_format(self):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     with self.assertRaises(ValueError) as e:
         d.unrelate('mysql', 'wordpress')
         self.assertEqual(
             str(e), 'All relations must be explicit, service:relation')
Example #13
0
 def test_action_do(self, mj):
     mj.return_value = '{"Action queued with id": "some-action-id"}'
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     mj.assert_has_calls(
         [call(['action', 'do', 'mysql/0', 'run', '--format', 'json'])])
Example #14
0
 def test_action_defined(self, mj):
     mj.return_value = '{"action": "description"}'
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     actions = d.action_defined('mysql')
     self.assertEquals(actions, {"action": "description"})
     mj.assert_has_calls(
         [call(['action', 'defined', 'mysql', '--format', 'json'])])
Example #15
0
 def test_init(self):
     d = Deployment(juju_env='gojuju')
     self.assertEqual('precise', d.series)
     self.assertEqual('gojuju', d.juju_env)
     self.assertEqual({}, d.services)
     self.assertEqual(True, d.use_sentries)
     self.assertEqual({}, d._sentries)
     self.assertEqual([], d.relations)
     d.cleanup()
Example #16
0
    def test_add_branch(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:~foo/charms/precise/baz/trunk'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('bar', 'cs:~foo/baz')
        self.assertEqual({'bar': {'branch': 'lp:~foo/charms/precise/baz/trunk',
                                  'num_units': 1}}, d.services)
Example #17
0
    def test_add_units(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('charm', units=2)
        self.assertEqual({'charm': {'branch': 'lp:charms/charm',
                                    'num_units': 2}}, d.services)
Example #18
0
    def test_relate(self, mcharm):
        a = mcharm.return_value
        a.provides = {'f': {'interface': 'test'}}
        a.requires = {'b': {'interface': 'test'}}

        d = Deployment(juju_env='gojuju')
        d.add('bar')
        d.add('foo')
        d.relate('foo:f', 'bar:b')
        self.assertEqual(d.relations, [['foo:f', 'bar:b']])
Example #19
0
    def test_add(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location':
                             'lp:~charmers/charms/precise/charm/trunk'}
        charm.url = 'cs:precise/charm'

        d = Deployment(juju_env='gojuju')
        d.add('charm')
        self.assertEqual({'charm': {'charm': 'cs:precise/charm',
                                    'num_units': 1}}, d.services)
Example #20
0
 def test_load(self):
     d = Deployment(juju_env='gojuju')
     schema = '{"gojuju": {"series": "raring", "services": {"wordpress": \
               {"branch": "lp:charms/wordpress"}, "mysql": {"options": \
               {"tuning": "fastest"}, "branch": "lp:charms/mysql"}}, \
               "relations": [["mysql:db", "wordpress:db"]]}}'
     dmap = json.loads(schema)
     d.load(dmap)
     self.assertEqual(dmap['gojuju']['services'], d.services)
     self.assertEqual(dmap['gojuju']['relations'], d.relations)
     self.assertEqual(dmap['gojuju']['series'], d.series)
Example #21
0
 def test_schema(self):
     d = Deployment(juju_env='gojuju', sentries=False)
     d.add('mysql')
     d.configure('mysql', tuning='fastest')
     d.add('wordpress')
     d.relate('mysql:db', 'wordpress:db')
     schema = {'gojuju': {'services': {'mysql': {'branch':
               'lp:charms/mysql', 'options': {'tuning': 'fastest'}},
              'wordpress': {'branch': 'lp:charms/wordpress'}}, 'series':
              'precise', 'relations': [['mysql:db', 'wordpress:db']]}}
     self.assertEqual(schema, d.schema())
Example #22
0
 def test_action_fetch_full_output(self, mj):
     action_output = ['{"Action queued with id": "some-action-id"}',
                      '{"results":{"key":"value"},"status":"completed",'
                      '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",'
                      '"enqueued":"2015-07-21 09:05:06 +0300 EEST",'
                      '"started":"2015-07-21 09:05:09 +0300 EEST"}}']
     mj.side_effect = action_output
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     results = d.action_fetch(uuid, full_output=True)
     self.assertEquals(results, json.loads(action_output[1]))
Example #23
0
    def test_load(self):
        d = Deployment(juju_env='gojuju')
        schema = '{"gojuju": {"series": "raring", "services": {"wordpress": \
                  {"branch": "lp:charms/wordpress"}, "mysql": {"options": \
                  {"tuning": "fastest"}, "branch": "lp:charms/mysql"}}, \
                  "relations": [["mysql:db", "wordpress:db"]]}}'

        dmap = json.loads(schema)
        d.load(dmap)
        self.assertEqual(dmap['gojuju']['services'], d.services)
        self.assertEqual(dmap['gojuju']['relations'], d.relations)
        self.assertEqual(dmap['gojuju']['series'], d.series)
Example #24
0
    def test_add_units(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('charm', units=2)
        self.assertEqual(
            {'charm': {
                'branch': 'lp:charms/charm',
                'num_units': 2
            }}, d.services)
Example #25
0
 def test_action_fetch_nowait_fail(self, mj):
     mj.side_effect = ['{"Action queued with id": "some-action-id"}',
                       '{"status":"running",'
                       '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",'
                       '"started":"2015-07-21 09:51:04 +0300 EEST"}}']
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     results = d.action_fetch(uuid, timeout=None)
     self.assertEquals(results, {})
     mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json']),
                          call(['action', 'fetch', 'some-action-id', '--format', 'json'])])
Example #26
0
 def test_remove(self, get_charm):
     d = Deployment(juju_env='gojuju')
     d.add('charm1')
     d.add('charm2')
     p1 = patch.object(d, 'remove_unit')
     p2 = patch.object(d, 'remove_service')
     self.addCleanup(p1.stop)
     self.addCleanup(p2.stop)
     remove_unit = p1.start()
     remove_service = p2.start()
     with patch('amulet.deployer.juju'):
         d.remove('charm1/0', 'charm2')
         remove_unit.assert_called_once_with('charm1/0')
         remove_service.assert_called_once_with('charm2')
Example #27
0
    def test_configure(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {
            'location': 'lp:~charmers/charms/precise/wordpress/trunk'
        }
        charm.url = 'cs:precise/wordpress'

        d = Deployment(juju_env='gojuju')
        d.add('wordpress')
        d.configure('wordpress', {'tuning': 'optimized'})
        d.configure('wordpress', {'wp-content': 'f', 'port': 100})
        self.assertEqual(
            {
                'wordpress': {
                    'charm': 'cs:precise/wordpress',
                    'series': 'precise',
                    'num_units': 1,
                    'options': {
                        'tuning': 'optimized',
                        'wp-content': 'f',
                        'port': 100
                    }
                }
            }, d.services)
Example #28
0
 def test_remove_unit(self, mj):
     d = Deployment(juju_env='gogo')
     d.add('mysql', units=2)
     d.deployed = True
     d.remove_unit('mysql/1')
     mj.assert_called_with(['remove-unit', 'mysql/1'])
     d.cleanup()
Example #29
0
 def test_action_fetch_wait(self, mj):
     mj.side_effect = ['{"Action queued with id": "some-action-id"}',
                       '{"results":{"key":"value"},"status":"completed",'
                       '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",'
                       '"enqueued":"2015-07-21 09:05:06 +0300 EEST",'
                       '"started":"2015-07-21 09:05:09 +0300 EEST"}}']
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     results = d.action_fetch(uuid)
     self.assertEquals(results, {'key': 'value'})
     mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json']),
                          call(['action', 'fetch', 'some-action-id', '--format', 'json', '--wait', '600'])])
Example #30
0
    def test_expose(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location':
                             'lp:~charmers/charms/precise/wordpress/trunk'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('wordpress')
        d.expose('wordpress')
        self.assertEqual(
            {'wordpress':
                {'branch': 'lp:~charmers/charms/precise/wordpress/trunk',
                 'num_units': 1,
                 'expose': True}}, d.services)
Example #31
0
    def test_add_branch(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:~foo/charms/precise/baz/trunk'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('bar', 'cs:~foo/baz')
        self.assertEqual(
            {
                'bar': {
                    'branch': 'lp:~foo/charms/precise/baz/trunk',
                    'num_units': 1
                }
            }, d.services)
Example #32
0
    def test_add(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {
            'location': 'lp:~charmers/charms/precise/charm/trunk'
        }
        charm.url = 'cs:precise/charm'

        d = Deployment(juju_env='gojuju')
        d.add('charm')
        self.assertEqual(
            {'charm': {
                'charm': 'cs:precise/charm',
                'num_units': 1
            }}, d.services)
Example #33
0
    def test_load(self):
        d = Deployment(juju_env='gojuju')
        schema = '{"mybundle": {"series": "raring", "services": {"wordpress": \
                  {"branch": "lp:~charmers/charms/precise/wordpress/trunk", \
                  "expose": true, "storage": {"wp-data": "rootfs,100M"}}, \
                  "mysql": {"options": {"tuning": "fastest"}, "constraints": \
                  "mem=2G cpu-cores=2", "branch": \
                  "lp:~charmers/charms/precise/mysql/trunk"}}, "relations": \
                  [["mysql:db", "wordpress:db"]]}}'

        dmap = json.loads(schema)
        with patch.object(d, 'add') as add:
            with patch.object(d, 'configure') as configure:
                with patch.object(d, 'expose') as expose:
                    d.load(dmap)
        self.assertEqual(d.juju_env, 'gojuju')
        self.assertEqual(dmap['mybundle']['relations'], d.relations)
        self.assertEqual(dmap['mybundle']['series'], d.series)
        add.assert_has_calls([
            call('wordpress',
                 placement=None,
                 series='raring',
                 storage={"wp-data": "rootfs,100M"},
                 units=1,
                 branch='lp:~charmers/charms/precise/wordpress/trunk',
                 constraints=None,
                 charm=None),
            call('mysql',
                 placement=None,
                 series='raring',
                 storage=None,
                 units=1,
                 branch='lp:~charmers/charms/precise/mysql/trunk',
                 constraints={
                     'mem': '2G',
                     'cpu-cores': '2'
                 },
                 charm=None)
        ],
                             any_order=True)
        configure.assert_has_calls([
            call('mysql', {'tuning': 'fastest'}),
        ])
        expose.assert_has_calls([
            call('wordpress'),
        ])
Example #34
0
 def test_init(self):
     d = Deployment(juju_env='gojuju')
     self.assertEqual('precise', d.series)
     self.assertEqual('gojuju', d.juju_env)
     self.assertEqual({}, d.services)
     self.assertEqual(True, d.use_sentries)
     self.assertEqual({}, d._sentries)
     self.assertEqual([], d.relations)
Example #35
0
    def test_add_constraints(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('charm', units=2, constraints=OrderedDict([
            ("cpu-power", 0),
            ("cpu-cores", 4),
            ("mem", "512M")
        ]))

        self.assertEqual({'charm': {'branch': 'lp:charms/charm',
                                    'constraints':
                                    'cpu-power=0 cpu-cores=4 mem=512M',
                                    'num_units': 2}}, d.services)
Example #36
0
 def test_configure(self):
     d = Deployment(juju_env='gojuju')
     d.add('wordpress')
     d.configure('wordpress', tuning='optimized')
     d.configure('wordpress', **{'wp-content': 'f', 'port': 100})
     self.assertEqual({'wordpress': {'branch': 'lp:charms/wordpress',
                      'options': {'tuning': 'optimized', 'wp-content': 'f',
                       'port': 100}}}, d.services)
Example #37
0
 def test_unrelate(self, mj):
     d = Deployment(juju_env='gogo')
     d._relate('mysql:db', 'charm:db')
     d.deployed = True
     d.unrelate('mysql:db', 'charm:db')
     mj.assert_has_calls([
         call(['remove-relation', 'mysql:db', 'charm:db']),
     ])
Example #38
0
    def test_add_storage(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('charm', storage={"mystorage": "ebs,10g,1"})
        self.assertEqual(
            {
                'charm': {
                    'branch': 'lp:charms/charm',
                    'num_units': 1,
                    'series': 'precise',
                    'storage': {
                        "mystorage": "ebs,10g,1"
                    }
                }
            }, d.services)
Example #39
0
 def test_load(self):
     d = Deployment(juju_env='gojuju')
     schema = '{"mybundle": {"series": "raring", "services": {"wordpress": \
               {"branch": "lp:~charmers/charms/precise/wordpress/trunk"}, \
               "mysql": {"options": {"tuning": "fastest"}, \
               "branch": "lp:~charmers/charms/precise/mysql/trunk"}}, \
               "relations": [["mysql:db", "wordpress:db"]]}}'
     dmap = json.loads(schema)
     with patch.object(d, 'add') as add:
         d.load(dmap)
     self.assertEqual(d.juju_env, 'gojuju')
     self.assertEqual(dmap['mybundle']['relations'], d.relations)
     self.assertEqual(dmap['mybundle']['series'], d.series)
     add.assert_has_calls([
         call('wordpress', charm=None, units=1),
         call('mysql', charm=None, units=1)],
         any_order=True
     )
     d.cleanup()
Example #40
0
class DeploymentSpec(object):
    def __init__(self, series="xenial"):
        self.series = series
        self.deployment = Deployment(series=self.series)
        self._run_hooks("init")

    def deploy(self):
        self._run_hooks("pre_setup")
        try:
            self.deployment.setup(timeout=TIMEOUT)
            self.deployment.sentry.wait()
        except TimeoutError:
            msg = "The model did not set up in % seconds!" % TIMEOUT
            raise_status(SKIP, msg=msg)
        self._run_hooks("post_setup")

    def _run_hooks(self, prefix):
        for attribute in dir(self):
            if attribute.startswith("_%s" % prefix):
                getattr(self, attribute)()
Example #41
0
class DeploymentSpec(object):
    def __init__(self, series="trusty"):
        self.series = series
        self.deployment = Deployment(series=self.series)
        self._run_hooks("init")

    def deploy(self):
        self._run_hooks("pre_setup")
        try:
            self.deployment.setup(timeout=TIMEOUT)
            self.deployment.sentry.wait()
        except TimeoutError:
            msg = "The model did not set up in % seconds!" % TIMEOUT
            raise_status(SKIP, msg=msg)
        self._run_hooks("post_setup")

    def _run_hooks(self, prefix):
        for attribute in dir(self):
            if attribute.startswith("_%s" % prefix):
                getattr(self, attribute)()
Example #42
0
    def test_add_constraints(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('charm',
              units=2,
              constraints=OrderedDict([("cpu-power", 0), ("cpu-cores", 4),
                                       ("mem", "512M")]))

        self.assertEqual(
            {
                'charm': {
                    'branch': 'lp:charms/charm',
                    'constraints': 'cpu-power=0 cpu-cores=4 mem=512M',
                    'num_units': 2
                }
            }, d.services)
Example #43
0
    def test_configure(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location':
                             'lp:~charmers/charms/precise/wordpress/trunk'}
        charm.url = 'cs:precise/wordpress'

        d = Deployment(juju_env='gojuju')
        d.add('wordpress')
        d.configure('wordpress', {'tuning': 'optimized'})
        d.configure('wordpress', {'wp-content': 'f', 'port': 100})
        self.assertEqual({'wordpress':
                          {'charm': 'cs:precise/wordpress',
                           'options': {'tuning': 'optimized',
                                       'wp-content': 'f',
                                       'port': 100}}}, d.services)
        d.cleanup()
Example #44
0
    def test_add_unit_error(self, mcharm, subprocess, waiter_status,
                            environments, upload_scripts):
        def mock_unit_error(f, service, unit_name):
            def _mock_unit_error(juju_env):
                status = f(juju_env)
                unit = status['services'][service]['units'].get(unit_name)
                if not unit:
                    return status
                unit['agent-state'] = 'error'
                unit['agent-state-info'] = 'hook failed: install'
                return status

            return _mock_unit_error

        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None
        charm.series = 'precise'

        environments.return_value = yaml.safe_load(RAW_ENVIRONMENTS_YAML)

        d = Deployment(juju_env='gojuju')
        waiter_status.side_effect = mock_unit_error(self._make_mock_status(d),
                                                    'charm', 'charm/1')
        d.add('charm', units=1)
        d.setup()
        with patch('amulet.deployer.juju'):
            self.assertRaisesRegexp(
                Exception, 'Error on unit charm/1: hook failed: install',
                d.add_unit, 'charm')
Example #45
0
 def test_action_fetch_nowait_fail(self, mj):
     mj.side_effect = [
         '{"Action queued with id": "some-action-id"}',
         '{"status":"running",'
         '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",'
         '"started":"2015-07-21 09:51:04 +0300 EEST"}}'
     ]
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     results = d.action_fetch(uuid, timeout=None)
     self.assertEquals(results, {})
     if JUJU_VERSION.major == 1:
         mj.assert_has_calls([
             call(['action', 'do', 'mysql/0', 'run', '--format', 'json']),
             call(['action', 'fetch', 'some-action-id', '--format', 'json'])
         ])
     else:
         mj.assert_has_calls([
             call(['run-action', 'mysql/0', 'run', '--format', 'json']),
             call([
                 'show-action-output', 'some-action-id', '--format', 'json'
             ])
         ])
Example #46
0
 def test_remove_service(self, get_charm):
     d = Deployment(juju_env='gojuju')
     d.add('charm')
     patcher = patch.object(d, 'sentry', MagicMock(unit={'charm/0': 1}))
     self.addCleanup(patcher.stop)
     sentry = patcher.start()
     d.deployed = True
     d.relations = [('charm:rel', 'another:rel')]
     with patch('amulet.deployer.juju') as juju:
         d.remove_service('charm')
         juju.assert_called_once_with(['remove-service', 'charm'])
     self.assertFalse('charm/0' in sentry.unit)
     self.assertFalse('charm' in d.services)
     self.assertEqual(0, len(d.relations))
Example #47
0
 def test_action_fetch_wait(self, mj):
     mj.side_effect = [
         '{"Action queued with id": "some-action-id"}',
         '{"results":{"key":"value"},"status":"completed",'
         '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",'
         '"enqueued":"2015-07-21 09:05:06 +0300 EEST",'
         '"started":"2015-07-21 09:05:09 +0300 EEST"}}'
     ]
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     self.assertEquals(uuid, "some-action-id")
     results = d.action_fetch(uuid)
     self.assertEquals(results, {'key': 'value'})
     if JUJU_VERSION.major == 1:
         mj.assert_has_calls([
             call(['action', 'do', 'mysql/0', 'run', '--format', 'json']),
             call([
                 'action', 'fetch', 'some-action-id', '--format', 'json',
                 '--wait', '600'
             ])
         ])
     else:
         mj.assert_has_calls([
             call(['run-action', 'mysql/0', 'run', '--format', 'json']),
             call([
                 'show-action-output', 'some-action-id', '--format', 'json',
                 '--wait', '600'
             ])
         ])
Example #48
0
    def test_add_unit(self, mcharm, subprocess, waiter_status, environments):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None
        charm.series = 'precise'

        environments.return_value = yaml.safe_load(RAW_ENVIRONMENTS_YAML)

        d = Deployment(juju_env='gojuju')
        waiter_status.side_effect = self._make_mock_status(d)
        d.add('charm', units=1)
        d.setup()
        with patch('amulet.deployer.juju'):
            d.add_unit('charm')
        self.assertTrue('charm/1' in d.sentry.unit)

        d.cleanup()
Example #49
0
    def test_schema(self, mcharm):
        wpmock = MagicMock()
        mysqlmock = MagicMock()
        wpmock.subordinate = False
        wpmock.code_source = {'location':
                              'lp:~charmers/charms/precise/wordpress/trunk'}
        wpmock.requires = {'db': {'interface': 'mysql'}}
        wpmock.url = None
        mysqlmock.subordinate = False
        mysqlmock.code_source = {'location':
                                 'lp:~charmers/charms/precise/mysql/trunk'}
        mysqlmock.provides = {'db': {'interface': 'mysql'}}
        mysqlmock.url = None

        mcharm.side_effect = [mysqlmock, wpmock]
        d = Deployment(juju_env='gojuju', sentries=False)
        d.add('mysql')
        d.configure('mysql', {'tuning': 'fastest'})
        d.add('wordpress')
        d.relate('mysql:db', 'wordpress:db')
        schema = {'gojuju': {
            'services': {
                'mysql': {
                    'branch': 'lp:~charmers/charms/precise/mysql/trunk',
                    'num_units': 1,
                    'options': {'tuning': 'fastest'},
                    'series': 'precise',
                },
                'wordpress': {
                    'branch': 'lp:~charmers/charms/precise/wordpress/trunk',
                    'num_units': 1,
                    'series': 'precise',
                }
            },
            'series': 'precise',
            'relations': [['mysql:db', 'wordpress:db']],
            'machines': {},
        }}
        self.assertEqual(schema, d.schema())
Example #50
0
 def test_remove_unit(self, get_charm):
     d = Deployment(juju_env='gojuju')
     d.add('charm')
     patcher = patch.object(d, 'sentry', MagicMock(unit={'charm/0': 1}))
     self.addCleanup(patcher.stop)
     sentry = patcher.start()
     d.deployed = True
     with patch('amulet.deployer.juju') as juju:
         d.remove_unit('charm/0')
         juju.assert_called_once_with(['remove-unit', 'charm/0'])
     self.assertFalse('charm/0' in sentry.unit)
     self.assertEqual(0, d.services['charm']['num_units'])
Example #51
0
 def test_action_fetch_raise_on_timeout(self, mj):
     mj.side_effect = [
         '{"Action queued with id": "some-action-id"}',
         '{"status":"running",'
         '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",'
         '"started":"2015-07-21 09:51:04 +0300 EEST"}}'
     ]
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     with self.assertRaises(TimeoutError):
         d.action_fetch(uuid, timeout=None, raise_on_timeout=True)
Example #52
0
 def test_configure(self):
     d = Deployment(juju_env='gojuju')
     d.add('wordpress')
     d.configure('wordpress', tuning='optimized')
     d.configure('wordpress', **{'wp-content': 'f', 'port': 100})
     self.assertEqual(
         {
             'wordpress': {
                 'branch': 'lp:charms/wordpress',
                 'options': {
                     'tuning': 'optimized',
                     'wp-content': 'f',
                     'port': 100
                 }
             }
         }, d.services)
Example #53
0
 def test_get_sentry_relations_not_found(self):
     d = Deployment(juju_env='gogo')
     d.relations = []
     with self.assertRaises(LookupError) as e:
         d._get_sentry_relations('charm:db', 'mysql:db')
         self.assertEqual(
             str(e),
             'Could not find relation between charm:db and mysql:db')
     d.cleanup()
Example #54
0
 def test_unrelate(self, mj):
     d = Deployment(juju_env='gogo')
     d._relate('mysql:db', 'charm:db')
     d.deployed = True
     d.unrelate('mysql:db', 'charm:db')
     mj.assert_has_calls([
         call(['remove-relation',
               'mysql:db', 'charm:db']),
         ])
Example #55
0
    def test_relate(self, mcharm):
        a = mcharm.return_value
        a.provides = {'f': {'interface': 'test'}}
        a.requires = {'b': {'interface': 'test'}}

        d = Deployment(juju_env='gojuju')
        d.add('bar')
        d.add('foo')
        d.relate('foo:f', 'bar:b')
        self.assertEqual(d.relations, [['foo:f', 'bar:b']])
Example #56
0
    def test_add_unit(self, mcharm, subprocess, waiter_status, environments,
                      upload_scripts):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None
        charm.series = 'precise'

        environments.return_value = yaml.safe_load(RAW_ENVIRONMENTS_YAML)

        d = Deployment(juju_env='gojuju')

        waiter_status.side_effect = self._make_mock_status(d)
        d.add('charm', units=1)
        d.setup()
        with patch('amulet.deployer.juju') as j:
            d.add_unit('charm')
            j.assert_called_with(['add-unit', 'charm', '-n', '1'])
        self.assertTrue('charm/1' in d.sentry.unit)
        self.assertEqual(2, d.services['charm']['num_units'])
Example #57
0
 def test_remove(self, get_charm):
     d = Deployment(juju_env='gojuju')
     d.add('charm1')
     d.add('charm2')
     p1 = patch.object(d, 'remove_unit')
     p2 = patch.object(d, 'remove_service')
     self.addCleanup(p1.stop)
     self.addCleanup(p2.stop)
     remove_unit = p1.start()
     remove_service = p2.start()
     with patch('amulet.deployer.juju'):
         d.remove('charm1/0', 'charm2')
         remove_unit.assert_called_once_with('charm1/0')
         remove_service.assert_called_once_with('charm2')
Example #58
0
 def test_action_fetch_full_output(self, mj):
     action_output = [
         '{"Action queued with id": "some-action-id"}',
         '{"results":{"key":"value"},"status":"completed",'
         '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",'
         '"enqueued":"2015-07-21 09:05:06 +0300 EEST",'
         '"started":"2015-07-21 09:05:09 +0300 EEST"}}'
     ]
     mj.side_effect = action_output
     d = Deployment(juju_env='gojuju')
     d.add('mysql')
     uuid = d.action_do('mysql/0', 'run')
     results = d.action_fetch(uuid, full_output=True)
     self.assertEquals(results, json.loads(action_output[1]))
Example #59
0
    def test_add_unit_target(self, mcharm, subprocess, waiter_status,
                             environments, upload_scripts):
        """
        If target is given to Deployment.add_unit(), the 'juju' call
        will includde --to to make the unit be added to the given
        target.
        """
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {'location': 'lp:charms/charm'}
        charm.url = None
        charm.series = 'precise'

        environments.return_value = yaml.safe_load(RAW_ENVIRONMENTS_YAML)

        d = Deployment(juju_env='gojuju')

        waiter_status.side_effect = self._make_mock_status(d)
        d.add('charm', units=1)
        d.setup()
        with patch('amulet.deployer.juju') as j:
            d.add_unit('charm', target='lxc:0')
            j.assert_called_with(
                ['add-unit', 'charm', '-n', '1', '--to', 'lxc:0'])
Example #60
0
    def test_expose(self, mcharm):
        charm = mcharm.return_value
        charm.subordinate = False
        charm.code_source = {
            'location': 'lp:~charmers/charms/precise/wordpress/trunk'
        }
        charm.url = None

        d = Deployment(juju_env='gojuju')
        d.add('wordpress')
        d.expose('wordpress')
        self.assertEqual(
            {
                'wordpress': {
                    'branch': 'lp:~charmers/charms/precise/wordpress/trunk',
                    'num_units': 1,
                    'expose': True
                }
            }, d.services)