|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
13 | | -import re |
| 13 | + |
| 14 | +import json |
14 | 15 | import uuid |
15 | 16 |
|
16 | 17 | from openstackclient.tests.functional import base |
|
19 | 20 | class NetworkFlavorTests(base.TestCase): |
20 | 21 | """Functional tests for network flavor.""" |
21 | 22 |
|
22 | | - @classmethod |
23 | | - def setUpClass(cls): |
24 | | - # Set up some regex for matching below |
25 | | - cls.re_name = re.compile("name\s+\|\s+([^|]+?)\s+\|") |
26 | | - cls.re_enabled = re.compile("enabled\s+\|\s+(\S+)") |
27 | | - cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|") |
28 | | - cls.SERVICE_TYPE = 'L3_ROUTER_NAT' |
29 | | - |
30 | 23 | def test_network_flavor_delete(self): |
31 | 24 | """Test create, delete multiple""" |
32 | 25 | name1 = uuid.uuid4().hex |
33 | | - raw_output = self.openstack( |
34 | | - 'network flavor create --description testdescription --enable' |
35 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name1, |
36 | | - ) |
| 26 | + cmd_output = json.loads(self.openstack( |
| 27 | + 'network flavor create -f json --description testdescription ' |
| 28 | + '--enable --service-type L3_ROUTER_NAT ' + name1, |
| 29 | + )) |
37 | 30 | self.assertEqual( |
38 | 31 | name1, |
39 | | - re.search(self.re_name, raw_output).group(1)) |
| 32 | + cmd_output['name'], |
| 33 | + ) |
40 | 34 | self.assertEqual( |
41 | | - 'True', |
42 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 35 | + True, |
| 36 | + cmd_output['enabled'], |
| 37 | + ) |
43 | 38 | self.assertEqual( |
44 | 39 | 'testdescription', |
45 | | - re.search(self.re_description, raw_output).group(1)) |
| 40 | + cmd_output['description'], |
| 41 | + ) |
46 | 42 |
|
47 | 43 | name2 = uuid.uuid4().hex |
48 | | - raw_output = self.openstack( |
49 | | - 'network flavor create --description testdescription1 --disable' |
50 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name2, |
51 | | - ) |
| 44 | + cmd_output = json.loads(self.openstack( |
| 45 | + 'network flavor create -f json --description testdescription1 ' |
| 46 | + '--disable --service-type L3_ROUTER_NAT ' + name2, |
| 47 | + )) |
52 | 48 | self.assertEqual( |
53 | 49 | name2, |
54 | | - re.search(self.re_name, raw_output).group(1)) |
| 50 | + cmd_output['name'], |
| 51 | + ) |
55 | 52 | self.assertEqual( |
56 | | - 'False', |
57 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 53 | + False, |
| 54 | + cmd_output['enabled'], |
| 55 | + ) |
58 | 56 | self.assertEqual( |
59 | 57 | 'testdescription1', |
60 | | - re.search(self.re_description, raw_output).group(1)) |
61 | | - |
| 58 | + cmd_output['description'], |
| 59 | + ) |
62 | 60 | raw_output = self.openstack( |
63 | 61 | 'network flavor delete ' + name1 + " " + name2) |
64 | 62 | self.assertOutput('', raw_output) |
65 | 63 |
|
66 | 64 | def test_network_flavor_list(self): |
| 65 | + """Test create defaults, list filters, delete""" |
67 | 66 | name1 = uuid.uuid4().hex |
68 | | - raw_output = self.openstack( |
69 | | - 'network flavor create --description testdescription --enable' |
70 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name1, |
71 | | - ) |
| 67 | + cmd_output = json.loads(self.openstack( |
| 68 | + 'network flavor create -f json --description testdescription ' |
| 69 | + '--enable --service-type L3_ROUTER_NAT ' + name1, |
| 70 | + )) |
72 | 71 | self.addCleanup(self.openstack, "network flavor delete " + name1) |
73 | 72 | self.assertEqual( |
74 | 73 | name1, |
75 | | - re.search(self.re_name, raw_output).group(1)) |
| 74 | + cmd_output['name'], |
| 75 | + ) |
76 | 76 | self.assertEqual( |
77 | | - 'True', |
78 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 77 | + True, |
| 78 | + cmd_output['enabled'], |
| 79 | + ) |
79 | 80 | self.assertEqual( |
80 | 81 | 'testdescription', |
81 | | - re.search(self.re_description, raw_output).group(1)) |
| 82 | + cmd_output['description'], |
| 83 | + ) |
82 | 84 |
|
83 | 85 | name2 = uuid.uuid4().hex |
84 | | - raw_output = self.openstack( |
85 | | - 'network flavor create --description testdescription --disable' |
86 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name2, |
87 | | - ) |
| 86 | + cmd_output = json.loads(self.openstack( |
| 87 | + 'network flavor create -f json --description testdescription1 ' |
| 88 | + '--disable --service-type L3_ROUTER_NAT ' + name2, |
| 89 | + )) |
88 | 90 | self.assertEqual( |
89 | 91 | name2, |
90 | | - re.search(self.re_name, raw_output).group(1)) |
| 92 | + cmd_output['name'], |
| 93 | + ) |
91 | 94 | self.assertEqual( |
92 | | - 'False', |
93 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 95 | + False, |
| 96 | + cmd_output['enabled'], |
| 97 | + ) |
94 | 98 | self.assertEqual( |
95 | | - 'testdescription', |
96 | | - re.search(self.re_description, raw_output).group(1)) |
| 99 | + 'testdescription1', |
| 100 | + cmd_output['description'], |
| 101 | + ) |
97 | 102 | self.addCleanup(self.openstack, "network flavor delete " + name2) |
98 | 103 |
|
99 | 104 | # Test list |
100 | | - raw_output = self.openstack('network flavor list') |
101 | | - self.assertIsNotNone(raw_output) |
102 | | - self.assertIsNotNone(re.search(name1, raw_output)) |
103 | | - self.assertIsNotNone(re.search(name2, raw_output)) |
| 105 | + cmd_output = json.loads(self.openstack( |
| 106 | + 'network flavor list -f json ',)) |
| 107 | + self.assertIsNotNone(cmd_output) |
| 108 | + |
| 109 | + name_list = [item.get('Name') for item in cmd_output] |
| 110 | + self.assertIn(name1, name_list) |
| 111 | + self.assertIn(name2, name_list) |
104 | 112 |
|
105 | 113 | def test_network_flavor_set(self): |
| 114 | + """Tests create options, set, show, delete""" |
106 | 115 | name = uuid.uuid4().hex |
107 | 116 | newname = name + "_" |
108 | | - raw_output = self.openstack( |
109 | | - 'network flavor create --description testdescription --enable' |
110 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name, |
111 | | - ) |
| 117 | + cmd_output = json.loads(self.openstack( |
| 118 | + 'network flavor create -f json --description testdescription ' |
| 119 | + '--disable --service-type L3_ROUTER_NAT ' + name, |
| 120 | + )) |
112 | 121 | self.addCleanup(self.openstack, "network flavor delete " + newname) |
113 | 122 | self.assertEqual( |
114 | 123 | name, |
115 | | - re.search(self.re_name, raw_output).group(1)) |
| 124 | + cmd_output['name'], |
| 125 | + ) |
116 | 126 | self.assertEqual( |
117 | | - 'True', |
118 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 127 | + False, |
| 128 | + cmd_output['enabled'], |
| 129 | + ) |
119 | 130 | self.assertEqual( |
120 | 131 | 'testdescription', |
121 | | - re.search(self.re_description, raw_output).group(1)) |
| 132 | + cmd_output['description'], |
| 133 | + ) |
122 | 134 |
|
123 | | - self.openstack( |
| 135 | + raw_output = self.openstack( |
124 | 136 | 'network flavor set --name ' + newname + ' --disable ' + name |
125 | 137 | ) |
126 | | - raw_output = self.openstack('network flavor show ' + newname) |
| 138 | + self.assertOutput('', raw_output) |
| 139 | + |
| 140 | + cmd_output = json.loads(self.openstack( |
| 141 | + 'network flavor show -f json ' + newname,)) |
127 | 142 | self.assertEqual( |
128 | 143 | newname, |
129 | | - re.search(self.re_name, raw_output).group(1)) |
| 144 | + cmd_output['name'], |
| 145 | + ) |
130 | 146 | self.assertEqual( |
131 | | - 'False', |
132 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 147 | + False, |
| 148 | + cmd_output['enabled'], |
| 149 | + ) |
133 | 150 | self.assertEqual( |
134 | 151 | 'testdescription', |
135 | | - re.search(self.re_description, raw_output).group(1)) |
| 152 | + cmd_output['description'], |
| 153 | + ) |
136 | 154 |
|
137 | 155 | def test_network_flavor_show(self): |
| 156 | + """Test show network flavor""" |
138 | 157 | name = uuid.uuid4().hex |
139 | | - self.openstack( |
140 | | - 'network flavor create --description testdescription --enable' |
141 | | - ' --service-type ' + self.SERVICE_TYPE + ' ' + name, |
142 | | - ) |
| 158 | + cmd_output = json.loads(self.openstack( |
| 159 | + 'network flavor create -f json --description testdescription ' |
| 160 | + '--disable --service-type L3_ROUTER_NAT ' + name, |
| 161 | + )) |
143 | 162 | self.addCleanup(self.openstack, "network flavor delete " + name) |
144 | | - raw_output = self.openstack('network flavor show ' + name) |
| 163 | + cmd_output = json.loads(self.openstack( |
| 164 | + 'network flavor show -f json ' + name,)) |
145 | 165 | self.assertEqual( |
146 | 166 | name, |
147 | | - re.search(self.re_name, raw_output).group(1)) |
| 167 | + cmd_output['name'], |
| 168 | + ) |
148 | 169 | self.assertEqual( |
149 | | - 'True', |
150 | | - re.search(self.re_enabled, raw_output).group(1)) |
| 170 | + False, |
| 171 | + cmd_output['enabled'], |
| 172 | + ) |
151 | 173 | self.assertEqual( |
152 | 174 | 'testdescription', |
153 | | - re.search(self.re_description, raw_output).group(1)) |
| 175 | + cmd_output['description'], |
| 176 | + ) |
0 commit comments