def test_storage_joined_single_device(self, mock_kvstore, mock_local_unit, mock_rel_set, mock_environ): mock_environ.get.side_effect = {'JUJU_ENV_UUID': uuid.uuid4()} mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.determine_block_devices.return_value = ['/dev/vdb'] hooks.swift_storage_relation_joined() mock_rel_set.assert_called_with( relation_id=None, device='vdb', object_port=6000, account_port=6002, zone=1, container_port=6001 ) kvstore.get.return_value = None rel_settings = {} def fake_kv_set(key, value): rel_settings[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return rel_settings.get(key) kvstore.get.side_effect = fake_kv_get devices = {"vdb@%s" % (mock_environ['JUJU_ENV_UUID']): {"status": "active", "blkid": 'a-test-uuid'}} kvstore.set.assert_called_with(key='devices', value=json.dumps(devices))
def test_storage_joined_dev_exists_unknown_juju_env_uuid(self, mock_kvstore, mock_local_unit, mock_environ): mock_environ.get.return_value = {'JUJU_ENV_UUID': uuid.uuid4()} self.determine_block_devices.return_value = ['/dev/vdb', '/dev/vdc', '/dev/vdd'] mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None store = {'vdb@%s' % (uuid.uuid4()): {"status": "active", "blkid": 'vdb-blkid-uuid'}} def fake_kv_set(key, value): store[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return store.get(key) kvstore.get.side_effect = fake_kv_get hooks.swift_storage_relation_joined() env_uuid = mock_environ['JUJU_ENV_UUID'] devices = {"vdb@%s" % (env_uuid): {"status": "active", "blkid": 'vdb-blkid-uuid'}, "vdd@%s" % (env_uuid): {"status": "active", "blkid": 'vdd-blkid-uuid'}, "vdc@%s" % (env_uuid): {"status": "active", "blkid": 'vdc-blkid-uuid'}} kvstore.set.assert_called_with( key='devices', value=json.dumps(devices) )
def test_storage_joined_multi_device(self, mock_kvstore, mock_local_unit, mock_environ): test_uuid = uuid.uuid4() test_environ = {'JUJU_ENV_UUID': test_uuid} mock_environ.get.side_effect = test_environ.get self.determine_block_devices.return_value = ['/dev/vdb', '/dev/vdc', '/dev/vdd'] mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None rel_settings = {} def fake_kv_set(key, value): rel_settings[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return rel_settings.get(key) kvstore.get.side_effect = fake_kv_get hooks.swift_storage_relation_joined() devices = {"vdb@%s" % (test_uuid): {"status": "active", "blkid": 'vdb-blkid-uuid'}, "vdd@%s" % (test_uuid): {"status": "active", "blkid": 'vdd-blkid-uuid'}, "vdc@%s" % (test_uuid): {"status": "active", "blkid": 'vdc-blkid-uuid'}} kvstore.set.assert_called_with( key='devices', value=json.dumps(devices) )
def _test_storage_joined_single_device(self, mock_kvstore, mock_local_unit, mock_rel_set, mock_environ, env_key): test_uuid = uuid.uuid4() test_environ = {env_key: test_uuid} mock_environ.get.side_effect = test_environ.get mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.test_kv.set('prepared-devices', ['/dev/vdb']) self.network_get_primary_address.return_value = "10.10.10.2" # py3 is very picky, and log is only patched in # hooks.swift_storage_hooks with patch('lib.swift_storage_utils.log'): hooks.swift_storage_relation_joined() self.get_relation_ip.assert_called_once_with('swift-storage') mock_rel_set.assert_called_with(relation_id=None, relation_settings={ "ip_cls": "10.10.10.2", "ip_rep": "10.10.10.2", "private-address": "10.10.10.2", "region": 1, "zone": 1, "device": 'vdb', "account_port": 6002, "account_port_rep": 6012, "container_port": 6001, "container_port_rep": 6011, "object_port": 6000, "object_port_rep": 6010 }) kvstore.get.return_value = None rel_settings = {} def fake_kv_set(key, value): rel_settings[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return rel_settings.get(key) kvstore.get.side_effect = fake_kv_get devices = { "vdb@%s" % (test_uuid): { "status": "active", "blkid": 'a-test-uuid' } } kvstore.set.assert_called_with(key='devices', value=json.dumps(devices, sort_keys=True))
def test_storage_joined_dev_exists_unknown_juju_env_uuid( self, mock_kvstore, mock_local_unit, mock_environ): test_uuid = uuid.uuid4() test_environ = {'JUJU_ENV_UUID': test_uuid} mock_environ.get.side_effect = test_environ.get self.test_kv.set('prepared-devices', ['/dev/vdb', '/dev/vdc', '/dev/vdd']) mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None store = { 'vdb@%s' % (uuid.uuid4()): { "status": "active", "blkid": 'vdb-blkid-uuid' } } def fake_kv_set(key, value): store[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return store.get(key) kvstore.get.side_effect = fake_kv_get # py3 is very picky, and log is only patched in # hooks.swift_storage_hooks with patch('lib.swift_storage_utils.log'): hooks.swift_storage_relation_joined() devices = { "vdb@%s" % (test_uuid): { "status": "active", "blkid": 'vdb-blkid-uuid' }, "vdd@%s" % (test_uuid): { "status": "active", "blkid": 'vdd-blkid-uuid' }, "vdc@%s" % (test_uuid): { "status": "active", "blkid": 'vdc-blkid-uuid' } } kvstore.set.assert_called_with(key='devices', value=json.dumps(devices, sort_keys=True)) self.get_relation_ip.assert_called_once_with('swift-storage')
def _test_storage_joined_single_device(self, mock_kvstore, mock_local_unit, mock_rel_set, mock_environ, env_key): test_uuid = uuid.uuid4() test_environ = {env_key: test_uuid} mock_environ.get.side_effect = test_environ.get mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.test_kv.set('prepared-devices', ['/dev/vdb']) # py3 is very picky, and log is only patched in # hooks.swift_storage_hooks with patch('lib.swift_storage_utils.log'): hooks.swift_storage_relation_joined() self.get_relation_ip.assert_called_once_with('swift-storage') mock_rel_set.assert_called_with( relation_id=None, relation_settings={ "device": 'vdb', "object_port": 6000, "account_port": 6002, "zone": 1, "container_port": 6001, "private-address": "10.10.10.2" } ) kvstore.get.return_value = None rel_settings = {} def fake_kv_set(key, value): rel_settings[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return rel_settings.get(key) kvstore.get.side_effect = fake_kv_get devices = {"vdb@%s" % (test_uuid): {"status": "active", "blkid": 'a-test-uuid'}} kvstore.set.assert_called_with( key='devices', value=json.dumps(devices, sort_keys=True))
def _test_storage_joined_single_device(self, mock_kvstore, mock_local_unit, mock_rel_set, mock_environ, env_key): test_uuid = uuid.uuid4() test_environ = {env_key: test_uuid} mock_environ.get.side_effect = test_environ.get mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.determine_block_devices.return_value = ['/dev/vdb'] hooks.swift_storage_relation_joined() self.get_relation_ip.assert_called_once_with('swift-storage') mock_rel_set.assert_called_with(relation_id=None, relation_settings={ "device": 'vdb', "object_port": 6000, "account_port": 6002, "zone": 1, "container_port": 6001, "private-address": "10.10.10.2" }) kvstore.get.return_value = None rel_settings = {} def fake_kv_set(key, value): rel_settings[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return rel_settings.get(key) kvstore.get.side_effect = fake_kv_get devices = { "vdb@%s" % (test_uuid): { "status": "active", "blkid": 'a-test-uuid' } } kvstore.set.assert_called_with(key='devices', value=json.dumps(devices))
def test_storage_joined_ipv6(self, mock_kvstore, mock_rel_set, mock_environ): kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.determine_block_devices.return_value = ['/dev/vdb'] self.test_config.set('prefer-ipv6', True) self.get_ipv6_addr.return_value = ['2001:db8:1::1'] hooks.swift_storage_relation_joined() args = { 'relation_id': None, 'device': 'vdb', 'object_port': 6000, 'account_port': 6002, 'zone': 1, 'container_port': 6001, 'private-address': '2001:db8:1::1', } mock_rel_set.assert_called_with(**args) kvstore.get.assert_called_with(key='devices')
def test_storage_joined_ipv6(self, mock_kvstore, mock_rel_set, mock_environ): kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None self.determine_block_devices.return_value = ['/dev/vdb'] self.test_config.set('prefer-ipv6', True) self.get_ipv6_addr.return_value = ['2001:db8:1::1'] hooks.swift_storage_relation_joined() args = { 'relation_id': None, 'device': 'vdb', 'object_port': 6000, 'account_port': 6002, 'zone': 1, 'container_port': 6001, 'private-address': '2001:db8:1::1', } mock_rel_set.assert_called_with(**args) kvstore.get.assert_called_with(key='devices')
def test_storage_joined_dev_exists_unknown_juju_env_uuid(self, mock_kvstore, mock_local_unit, mock_environ): test_uuid = uuid.uuid4() test_environ = {'JUJU_ENV_UUID': test_uuid} mock_environ.get.side_effect = test_environ.get self.test_kv.set('prepared-devices', ['/dev/vdb', '/dev/vdc', '/dev/vdd']) mock_local_unit.return_value = 'test/0' kvstore = mock_kvstore.return_value kvstore.__enter__.return_value = kvstore kvstore.get.return_value = None store = {'vdb@%s' % (uuid.uuid4()): {"status": "active", "blkid": 'vdb-blkid-uuid'}} def fake_kv_set(key, value): store[key] = value kvstore.set.side_effect = fake_kv_set def fake_kv_get(key): return store.get(key) kvstore.get.side_effect = fake_kv_get # py3 is very picky, and log is only patched in # hooks.swift_storage_hooks with patch('lib.swift_storage_utils.log'): hooks.swift_storage_relation_joined() devices = {"vdb@%s" % (test_uuid): {"status": "active", "blkid": 'vdb-blkid-uuid'}, "vdd@%s" % (test_uuid): {"status": "active", "blkid": 'vdd-blkid-uuid'}, "vdc@%s" % (test_uuid): {"status": "active", "blkid": 'vdc-blkid-uuid'}} kvstore.set.assert_called_with( key='devices', value=json.dumps(devices, sort_keys=True) ) self.get_relation_ip.assert_called_once_with('swift-storage')