예제 #1
0
    def test_add_unit_error(self, mcharm, subprocess, waiter_status, environments):
        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')
        d.cleanup()
예제 #2
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()
예제 #3
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()
예제 #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()
예제 #5
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',
            'options': {'tuning': 'fastest'}},
            'wordpress': {'branch':
                          'lp:~charmers/charms/precise/wordpress/trunk'}},
            'series': 'precise', 'relations': [['mysql:db', 'wordpress:db']]}}
        self.assertEqual(schema, d.schema())
        d.cleanup()
예제 #6
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')
     d.cleanup()
예제 #7
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()
예제 #8
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()
예제 #9
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']])
        d.cleanup()
예제 #10
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)
        d.cleanup()
예제 #11
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'}}, d.services)
        d.cleanup()
예제 #12
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'}},
                         d.services)
        d.cleanup()
예제 #13
0
 def test_get_sentry_relations(self):
     d = Deployment(juju_env='gogo')
     d.relations = [
         ['relation-sentry:provides-mysql_db-charm_db', 'mysql:db'],
         ['relation-sentry:requires-mysql_db-charm_db', 'charm:db'],
     ]
     self.assertEqual(
         d._get_sentry_relations('charm:db', 'mysql:db'),
         d.relations)
     self.assertEqual(
         d._get_sentry_relations('mysql:db', 'charm:db'),
         list(reversed(d.relations)))
     d.cleanup()
예제 #14
0
 def test_load(self):
     d = Deployment(juju_env='gojuju')
     schema = '{"gojuju": {"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)
     d.load(dmap)
     self.assertEqual(dmap['gojuju']['services'], d.services)
     self.assertEqual(dmap['gojuju']['relations'], d.relations)
     self.assertEqual(dmap['gojuju']['series'], d.series)
     d.cleanup()
예제 #15
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',
                           'expose': True}}, d.services)
        d.cleanup()
예제 #16
0
    def test_unrelate(self, mj, _get_sentry_relations):
        _get_sentry_relations.return_value = [
            ['relation-sentry:provides-mysql_db-charm_db', 'mysql:db'],
            ['relation-sentry:requires-mysql_db-charm_db', 'charm:db'],
        ]

        d = Deployment(juju_env='gogo')
        d.deployed = True
        d.unrelate('mysql:db', 'charm:db')
        mj.assert_has_calls([
            call(['remove-relation',
                  'relation-sentry:provides-mysql_db-charm_db', 'mysql:db']),
            call(['remove-relation',
                  'relation-sentry:requires-mysql_db-charm_db', 'charm:db']),
            ])
        d.cleanup()
예제 #17
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()
예제 #18
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)
        d.cleanup()
예제 #19
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()
예제 #20
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()
예제 #21
0
 def test_remove_unit_not_deployed(self):
     d = Deployment(juju_env='gogo')
     d.add('mysql', units=2)
     d.deployed = True
     self.assertRaises(ValueError, d.remove_unit, 'wordpress/1')
     d.cleanup()
예제 #22
0
 def test_remove_unit_not_deployed(self):
     d = Deployment(juju_env='gogo')
     d.add('mysql', units=2)
     self.assertRaises(NotImplementedError, d.remove_unit, 'mysql/0')
     d.cleanup()
예제 #23
0
 def test_unrelate_post_deploy(self):
     d = Deployment(juju_env='gogo')
     self.assertRaises(NotImplementedError, d.unrelate, 'mysql:db',
                       'wordpress:db')
     d.cleanup()
예제 #24
0
 def test_unrelate(self, mj):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     d.unrelate('mysql', 'charm')
     mj.assert_called_with(['remove-relation', 'mysql', 'charm'])
     d.cleanup()
예제 #25
0
 def test_configure_not_deployed(self):
     d = Deployment(juju_env='gojuju')
     self.assertRaises(ValueError, d.configure, 'wordpress',
                       {'tuning': 'optimized'})
     d.cleanup()
예제 #26
0
 def test_add_post_deploy(self):
     d = Deployment(juju_env='gogo')
     d.deployed = True
     self.assertRaises(NotImplementedError, d.add, 'mysql')
     d.cleanup()
예제 #27
0
 def test_juju_test_charm(self):
     d = Deployment(juju_env='gogo')
     self.assertEqual('charmbook', d.charm_name)
     d.cleanup()
예제 #28
0
 def test_expose_not_deployed(self):
     d = Deployment(juju_env='gojuju')
     self.assertRaises(ValueError, d.expose, 'wordpress')
     d.cleanup()
예제 #29
0
 def test_unrelate_not_enough(self):
     d = Deployment(juju_env='gogo')
     self.assertRaises(LookupError, d.unrelate, 'mysql')
     d.cleanup()
예제 #30
0
 def test_relate_not_deployed(self):
     d = Deployment(juju_env='gojuju')
     self.assertRaises(ValueError, d.relate, 'foo:f', 'bar:a')
     d.cleanup()