1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from snaps.domain.volume import (
18 QoSSpec, VolumeType, VolumeTypeEncryption, Volume)
21 class VolumeDomainObjectTests(unittest.TestCase):
23 Tests the construction of the snaps.domain.volume.Volume class
26 def test_construction_positional(self):
27 volume = Volume('name1', 'id1', 'desc_val1', 2, 'type_val1',
28 'avail_zone1', False, [{'attached_at': 'foo'}])
29 self.assertEqual('name1', volume.name)
30 self.assertEqual('id1', volume.id)
31 self.assertEqual('desc_val1', volume.description)
32 self.assertEqual(2, volume.size)
33 self.assertEqual('type_val1', volume.type)
34 self.assertEqual('avail_zone1', volume.availability_zone)
35 self.assertFalse(volume.multi_attach)
36 self.assertIsNotNone(volume.attachments)
37 self.assertTrue(isinstance(volume.attachments[0], dict))
38 self.assertEqual(1, len(volume.attachments))
40 def test_construction_named(self):
41 volume = Volume(attachments=[{'attached_at': 'foo'}],
42 multi_attach=True, availability_zone='avail_zone2',
43 vol_type='type_val2', size=3, description='desc_val2',
44 volume_id='id2', name='name2')
45 self.assertEqual('name2', volume.name)
46 self.assertEqual('id2', volume.id)
47 self.assertEqual('desc_val2', volume.description)
48 self.assertEqual(3, volume.size)
49 self.assertEqual('type_val2', volume.type)
50 self.assertEqual('avail_zone2', volume.availability_zone)
51 self.assertTrue(volume.multi_attach)
52 self.assertIsNotNone(volume.attachments)
53 self.assertTrue(isinstance(volume.attachments[0], dict))
54 self.assertEqual(1, len(volume.attachments))
57 class VolumeTypeDomainObjectTests(unittest.TestCase):
59 Tests the construction of the snaps.domain.volume.VolumeType class
62 def test_construction_positional(self):
63 encryption = VolumeTypeEncryption(
64 'id-encrypt1', 'id-vol-type1', 'loc1', 'provider1', 'cipher1', 99)
65 qos_spec = QoSSpec('name', 'id', 'consumer')
67 volume_type = VolumeType('name', 'id', True, encryption, qos_spec)
68 self.assertEqual('name', volume_type.name)
69 self.assertEqual('id', volume_type.id)
70 self.assertTrue(volume_type.public)
71 self.assertEqual(encryption, volume_type.encryption)
72 self.assertEqual(qos_spec, volume_type.qos_spec)
74 def test_construction_named(self):
75 encryption = VolumeTypeEncryption(
76 'id-encrypt1', 'id-vol-type1', 'loc1', 'provider1', 'cipher1', 99)
77 qos_spec = QoSSpec('name', 'id', 'consumer')
79 volume_type = VolumeType(
80 qos_spec=qos_spec, encryption=encryption, volume_type_id='id',
81 name='name', public='true')
82 self.assertEqual('name', volume_type.name)
83 self.assertEqual('id', volume_type.id)
84 self.assertTrue(volume_type.public)
85 self.assertEqual(encryption, volume_type.encryption)
86 self.assertEqual(qos_spec, volume_type.qos_spec)
89 class VolumeTypeEncryptionObjectTests(unittest.TestCase):
91 Tests the construction of the snaps.domain.volume.VolumeTypeEncryption
95 def test_construction_positional(self):
96 encryption = VolumeTypeEncryption(
97 'id-encrypt1', 'id-vol-type1', 'loc1', 'provider1', 'cipher1', 99)
98 self.assertEqual('id-encrypt1', encryption.id)
99 self.assertEqual('id-vol-type1', encryption.volume_type_id)
100 self.assertEqual('loc1', encryption.control_location)
101 self.assertEqual('provider1', encryption.provider)
102 self.assertEqual('cipher1', encryption.cipher)
103 self.assertEqual(99, encryption.key_size)
105 def test_construction_named(self):
106 encryption = VolumeTypeEncryption(
107 key_size=89, cipher='cipher2', provider='provider2',
108 control_location='loc2', volume_type_id='id-vol-type2',
109 volume_encryption_id='id-encrypt2')
110 self.assertEqual('id-encrypt2', encryption.id)
111 self.assertEqual('id-vol-type2', encryption.volume_type_id)
112 self.assertEqual('loc2', encryption.control_location)
113 self.assertEqual('provider2', encryption.provider)
114 self.assertEqual('cipher2', encryption.cipher)
115 self.assertEqual(89, encryption.key_size)
118 class QoSSpecDomainObjectTests(unittest.TestCase):
120 Tests the construction of the snaps.domain.volume.QoSSpec class
123 def test_construction_positional(self):
124 qos_spec = QoSSpec('name', 'id', 'consumer')
125 self.assertEqual('name', qos_spec.name)
126 self.assertEqual('id', qos_spec.id)
127 self.assertEqual('consumer', qos_spec.consumer)
129 def test_construction_named(self):
130 qos_spec = QoSSpec(consumer='consumer', spec_id='id', name='name')
131 self.assertEqual('name', qos_spec.name)
132 self.assertEqual('id', qos_spec.id)
133 self.assertEqual('consumer', qos_spec.consumer)