~charmers/charms/trusty/galera-cluster/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_mysql.py

  • Committer: Edward Hope-Morley
  • Date: 2015-02-04 17:47:15 UTC
  • mfrom: (42.1.5 percona-cluster.fix-1389670)
  • Revision ID: edward.hope-morley@canonical.com-20150204174715-p5dhe9pq021v0xom
[hopem,r=]

Don't put allowed units onto the cluster relation.

Also fixes support for non-prefixed db relation
settings.

Closes-Bug: 1389670

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    @mock.patch('mysql.MySQLHelper', autospec=True)
16
16
    @mock.patch('mysql.relation_get')
17
17
    @mock.patch('mysql.related_units')
18
 
    @mock.patch('mysql.relation_ids')
19
18
    @mock.patch('mysql.log')
20
 
    def test_get_allowed_units(self, mock_log, mock_relation_ids,
21
 
                               mock_related_units, 
 
19
    def test_get_allowed_units(self, mock_log, mock_related_units, 
22
20
                               mock_relation_get, mock_helper,
23
21
                               mock_get_password):
24
 
        mock_relation_ids.return_value = ['r1']
25
 
        mock_related_units.return_value = ['ru1', 'ru2']
26
 
 
27
 
        def mock_rel_get(attribute, unit, rid):
28
 
            if unit == 'ru2':
29
 
                d = {'private-address': '1.2.3.4',
30
 
                     'dbA_hostname': json.dumps(['2.3.4.5', '6.7.8.9'])}
31
 
            else:
32
 
                d = {'private-address': '1.2.3.4'}
33
 
 
34
 
            return d.get(attribute, None)
 
22
 
 
23
        def mock_rel_get(unit, rid):
 
24
            if unit == 'unit/0':
 
25
                # Non-prefixed settings
 
26
                d = {'private-address': '10.0.0.1',
 
27
                     'hostname': 'hostA'}
 
28
            elif unit == 'unit/1':
 
29
                # Containing prefixed settings
 
30
                d = {'private-address': '10.0.0.2',
 
31
                     'dbA_hostname': json.dumps(['10.0.0.2', '2001:db8:1::2'])}
 
32
            elif unit == 'unit/2':
 
33
                # No hostname
 
34
                d = {'private-address': '10.0.0.3'}
 
35
 
 
36
            return d
35
37
 
36
38
        mock_relation_get.side_effect = mock_rel_get
 
39
        mock_related_units.return_value = ['unit/0', 'unit/1', 'unit/2']
 
40
 
37
41
        units = mysql.get_allowed_units('dbA', 'userA')
38
 
        mock_helper.return_value.grant_exists.assert_called_with('dbA',
39
 
                                                                 'userA',
40
 
                                                                 '6.7.8.9')
41
 
        self.assertEqual(units, set(['ru1', 'ru2']))
 
42
 
 
43
        calls = [mock.call('dbA', 'userA', 'hostA'),
 
44
                 mock.call().__nonzero__(),
 
45
                 mock.call('dbA', 'userA', '10.0.0.2'),
 
46
                 mock.call().__nonzero__(),
 
47
                 mock.call('dbA', 'userA', '2001:db8:1::2'),
 
48
                 mock.call().__nonzero__(),
 
49
                 mock.call('dbA', 'userA', '10.0.0.3'),
 
50
                 mock.call().__nonzero__()]
 
51
 
 
52
        mock_helper.return_value.grant_exists.assert_has_calls(calls)
 
53
        self.assertEqual(units, set(['unit/0', 'unit/1', 'unit/2']))