def test_set_related_resources_collection(self): volumes = [ Volume(self.client, resource_id='volume{}'.format(i)) for i in range(10) ] # init without related_resources collection lss = LSS(self.client, info={ 'volumes': { 'link': { 'rel': 'self', 'href': '/api/volumes' }, } }) for i in lss.related_resources_collection: self.assertEqual('', lss.representation.get(i)) self.assertFalse(hasattr(lss, i)) # loading related resources collection lss._start_updating() for item in ((DS8K_VOLUME, volumes), ): setattr(lss, item[0], item[1]) for j, value in enumerate(lss.representation[item[0]]): self.assertEqual(value, getattr(item[1][j], item[1][j].id_field)) lss._stop_updating()
def test_set_related_resources_collection(self): volumes = [Volume(self.client, resource_id='volume{}'.format(i)) for i in range(10) ] host_ports = \ [HostPort(self.client, resource_id='host_port{}'.format(i)) for i in range(10) ] ioports = [IOPort(self.client, resource_id='ioport{}'.format(i)) for i in range(10) ] # init without related_resources collection host = Host(self.client, info={ 'volumes': 'volumes', # string 'ioports': '', # empty 'host_ports': { # link 'link': { 'rel': 'self', 'href': '/api/v1//host_ports' }, } } ) for i in host.related_resources_collection: self.assertEqual('', host.representation.get(i)) self.assertFalse(hasattr(host, i)) # setting related resources collection for item in ((DS8K_VOLUME, volumes), (DS8K_IOPORT, ioports) ): setattr(host, item[0], item[1]) for j, value in enumerate(host.representation[item[0]]): self.assertEqual(value, getattr(item[1][j], item[1][j].id_field) ) for ind, v in enumerate(host._get_modified_info_dict()[item[0]]): self.assertEqual(v, getattr(item[1][ind], item[1][ind].id_field) ) # loading related resources collection host.volumes = [] host.ioports = [] host._start_updating() for item in ((DS8K_VOLUME, volumes), (DS8K_HOST_PORT, host_ports), (DS8K_IOPORT, ioports) ): setattr(host, item[0], item[1]) for j, value in enumerate(host.representation[item[0]]): self.assertEqual(value, getattr(item[1][j], item[1][j].id_field) ) host._stop_updating()
def test_related_resource_field(self): volume_info = get_response_data_by_type( DS8K_VOLUME)['data'][DS8K_VOLUME][0] pool_id = volume_info['pool'][Pool.id_field] lss_id = volume_info['lss']['id'] volume = Volume(self.client, info=volume_info) self.assertEqual(volume.pool, pool_id) self.assertEqual(volume.representation['pool'], pool_id) self.assertIsInstance(volume._pool, Pool) self.assertEqual(volume._pool.id, pool_id) self.assertEqual(volume.lss, lss_id) self.assertEqual(volume.representation['lss'], lss_id) self.assertIsInstance(volume._lss, LSS) self.assertEqual(volume._lss.id, lss_id) volume.pool = 'new_pool' self.assertEqual(volume.pool, 'new_pool') self.assertEqual(volume.representation['pool'], 'new_pool') with self.assertRaises(FieldReadOnly): volume.lss = 'new_lss'
def test_set_related_resources_collection(self): volumes = [ Volume(self.client, resource_id='volume{}'.format(i)) for i in range(10) ] tserep = [ TSERep(self.client, info={'pool': { 'name': 'testpool_0' }}), ] eserep = [ ESERep(self.client, info={'pool': { 'name': 'testpool_0' }}), ] # init without related_resources collection pool = Pool(self.client, info={ 'name': 'testpool_0', 'eserep': '', 'tserep': '', 'volumes': { 'link': { 'rel': 'self', 'href': '/api/volumes' }, } }) for i in pool.related_resources_collection: self.assertEqual('', pool.representation.get(i)) self.assertFalse(hasattr(pool, i)) # loading related resources collection pool._start_updating() for item in ( (DS8K_VOLUME, volumes), (DS8K_TSEREP, tserep), (DS8K_ESEREP, eserep), ): setattr(pool, item[0], item[1]) for j, value in enumerate(pool.representation[item[0]]): self.assertEqual(value, getattr(item[1][j], item[1][j].id_field)) pool._stop_updating()
def test_related_resources_collection(self): hosts = [ Host(self.client, resource_id='host{}'.format(i)) for i in range(10) ] flashcopies = [ FlashCopy(self.client, resource_id='fc{}'.format(i)) for i in range(10) ] pprc = [ PPRC(self.client, resource_id='pprc{}'.format(i)) for i in range(10) ] # init without related_resources collection volume = Volume(self.client, info={ 'name': 'a_0000', 'link': { 'rel': 'self', 'href': '/api/volumes/a_0000' }, 'hosts': { 'link': { 'rel': 'self', 'href': '/api/hosts' }, } }) for i in volume.related_resources_collection: self.assertEqual('', volume.representation.get(i)) self.assertFalse(hasattr(volume, i)) # loading related resources collection volume._start_updating() setattr(volume, types.DS8K_HOST, hosts) setattr(volume, types.DS8K_FLASHCOPY, flashcopies) setattr(volume, types.DS8K_PPRC, pprc) volume._stop_updating() for j, value in enumerate(volume.representation[types.DS8K_HOST]): self.assertEqual(value, getattr(hosts[j], hosts[j].id_field)) for k, value in enumerate(volume.representation[types.DS8K_FLASHCOPY]): self.assertEqual(value, getattr(flashcopies[k], flashcopies[k].id_field)) for vol, value in enumerate(volume.representation[types.DS8K_PPRC]): self.assertEqual(value, getattr(pprc[vol], pprc[vol].id_field))
def test_invalid_volume_type(self): with self.assertRaises(ValueError) as cm: Volume(self.client, volume_type='fake') self.assertEqual( INVALID_TYPE.format(', '.join(types.DS8K_VOLUME_TYPES)), str(cm.exception))
def setUp(self): super(TestVolume, self).setUp() self.volume = Volume(self.client, VolumeManager(self.client)) self.maxDiff = None