~openstack-charmers/charm-helpers/to_upstream

« back to all changes in this revision

Viewing changes to tests/contrib/storage/test_linux_ceph.py

  • Committer: Adam Gandelman
  • Date: 2013-09-23 18:35:59 UTC
  • Revision ID: adamg@canonical.com-20130923183559-doyqnrui0q0rk3s4
Checkin ensure_ceph_keyring() and tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
460
460
            'ceph: Formatting block device %s as '
461
461
            'filesystem %s.' % (device, fstype), level='INFO'
462
462
        )
 
463
 
 
464
    @patch.object(ceph_utils, 'relation_ids')
 
465
    @patch.object(ceph_utils, 'related_units')
 
466
    @patch.object(ceph_utils, 'relation_get')
 
467
    def test_ensure_ceph_keyring_no_relation_no_data(self, rget, runits, rids):
 
468
        rids.return_value = []
 
469
        self.assertEquals(False, ceph_utils.ensure_ceph_keyring(service='foo'))
 
470
        rids.return_value = ['ceph:0']
 
471
        runits.return_value = ['ceph/0']
 
472
        rget.return_value = ''
 
473
        self.assertEquals(False, ceph_utils.ensure_ceph_keyring(service='foo'))
 
474
 
 
475
    @patch.object(ceph_utils, '_keyring_path')
 
476
    @patch.object(ceph_utils, 'create_keyring')
 
477
    @patch.object(ceph_utils, 'relation_ids')
 
478
    @patch.object(ceph_utils, 'related_units')
 
479
    @patch.object(ceph_utils, 'relation_get')
 
480
    def test_ensure_ceph_keyring_with_data(self, rget, runits,
 
481
                                           rids, create, _path):
 
482
        rids.return_value = ['ceph:0']
 
483
        runits.return_value = ['ceph/0']
 
484
        rget.return_value = 'fookey'
 
485
        self.assertEquals(True,
 
486
                          ceph_utils.ensure_ceph_keyring(service='foo'))
 
487
        create.assert_called_with(service='foo', key='fookey')
 
488
        _path.assert_called_with('foo')
 
489
        self.assertFalse(self.check_call.called)
 
490
 
 
491
        _path.return_value = '/etc/ceph/client.foo.keyring'
 
492
        self.assertEquals(
 
493
            True,
 
494
            ceph_utils.ensure_ceph_keyring(
 
495
                service='foo', user='adam', group='users'))
 
496
        create.assert_called_with(service='foo', key='fookey')
 
497
        _path.assert_called_with('foo')
 
498
        self.check_call.assert_called_with([
 
499
            'chown',
 
500
            'adam.users',
 
501
            '/etc/ceph/client.foo.keyring'
 
502
        ])