Browse Source

Add --disable-discovery argument to physical network

Adds support for a '--disable-discovery' argument to the 'kayobe
physical network configure' command. This can be used to configure the
physical network after discovery of bare metal compute nodes is
complete, to return the network to a normal state. The interface
configuration to be applied is configured via
'switch_interface_config_disable_discovery'.

Essentially, this is the mirror of the '--enable-discovery' argument.

Change-Id: I40426a8fd22e51e8ea3350013a614dfbcf2afccf
Story: 2004048
Task: 27054
tags/5.0.0.0rc1
Mark Goddard 7 months ago
parent
commit
e3e48e93ce

+ 14
- 2
ansible/group_vars/switches/config View File

@@ -18,7 +18,19 @@ switch_config: []
18 18
 # file.
19 19
 switch_interface_config: {}
20 20
 
21
-# Interface configuration for hardware discovery. After discovery Neutron owns
22
-# the configuration of these ports. Has the same format as
21
+# Interface configuration for enabling hardware discovery. After discovery
22
+# Neutron owns the configuration of these ports. Has the same format as
23 23
 # switch_interface_config.
24
+# [DEPRECATED] Use switch_interface_config_enable_discovery.
24 25
 switch_interface_config_discovery: {}
26
+
27
+# Interface configuration for enabling hardware discovery. After discovery
28
+# Neutron owns the configuration of these ports. Has the same format as
29
+# switch_interface_config.
30
+# [DEPRECATED NAME] switch_interface_config_discovery.
31
+switch_interface_config_enable_discovery: "{{ switch_interface_config_discovery }}"
32
+
33
+# Interface configuration for disabling hardware discovery. After discovery
34
+# Neutron owns the configuration of these ports. Has the same format as
35
+# switch_interface_config.
36
+switch_interface_config_disable_discovery: {}

+ 11
- 2
ansible/physical-network.yml View File

@@ -9,6 +9,9 @@
9 9
     # Set this variable to True to configure the network for hardware
10 10
     # discovery.
11 11
     physical_network_enable_discovery: False
12
+    # Set this variable to True to deconfigure the network for hardware
13
+    # discovery.
14
+    physical_network_disable_discovery: False
12 15
     # Set this variable to a comma-separated list of names of interfaces to
13 16
     # configure in order to restrict configuration to a subset of interfaces.
14 17
     physical_network_interface_limit: ''
@@ -53,12 +56,18 @@
53 56
       group_by:
54 57
         key: "switches_in_display_mode_{{ physical_network_display | bool }}"
55 58
 
56
-    - name: Add discovery interface configuration when performing discovery
59
+    - name: Add discovery interface configuration when enabling discovery
57 60
       set_fact:
58 61
         switch_interface_config: >
59
-          {{ switch_interface_config | combine(switch_interface_config_discovery) }}
62
+          {{ switch_interface_config | combine(switch_interface_config_enable_discovery) }}
60 63
       when: physical_network_enable_discovery | bool
61 64
 
65
+    - name: Add discovery interface configuration when disabling discovery
66
+      set_fact:
67
+        switch_interface_config: >
68
+          {{ switch_interface_config | combine(switch_interface_config_disable_discovery) }}
69
+      when: physical_network_disable_discovery | bool
70
+
62 71
     - name: Restrict switch interfaces to requested subset by name
63 72
       set_fact:
64 73
         switch_interface_config: >

+ 9
- 2
kayobe/cli/commands.py View File

@@ -228,14 +228,19 @@ class PhysicalNetworkConfigure(KayobeAnsibleMixin, VaultMixin, Command):
228 228
         group.add_argument("--display", action="store_true",
229 229
                            help="display the candidate configuration and exit "
230 230
                                 "without applying it")
231
-        group.add_argument("--enable-discovery", action="store_true",
232
-                           help="configure the network for hardware discovery")
233 231
         group.add_argument("--interface-limit",
234 232
                            help="limit the switch interfaces to be configured "
235 233
                                 "by interface name")
236 234
         group.add_argument("--interface-description-limit",
237 235
                            help="limit the switch interfaces to be configured "
238 236
                                 "by interface description")
237
+        discovery = parser.add_mutually_exclusive_group()
238
+        discovery.add_argument("--enable-discovery", action="store_true",
239
+                               help="configure the network for hardware "
240
+                                    "discovery")
241
+        discovery.add_argument("--disable-discovery", action="store_true",
242
+                               help="deconfigure the network for hardware "
243
+                                    "discovery")
239 244
         return parser
240 245
 
241 246
     def take_action(self, parsed_args):
@@ -244,6 +249,8 @@ class PhysicalNetworkConfigure(KayobeAnsibleMixin, VaultMixin, Command):
244 249
         extra_vars["physical_network_display"] = parsed_args.display
245 250
         if parsed_args.enable_discovery:
246 251
             extra_vars["physical_network_enable_discovery"] = True
252
+        if parsed_args.disable_discovery:
253
+            extra_vars["physical_network_disable_discovery"] = True
247 254
         if parsed_args.interface_limit:
248 255
             extra_vars["physical_network_interface_limit"] = (
249 256
                 parsed_args.interface_limit)

+ 140
- 0
kayobe/tests/unit/cli/test_commands.py View File

@@ -67,6 +67,146 @@ class TestCase(unittest.TestCase):
67 67
         ]
68 68
         self.assertEqual(expected_calls, mock_run.call_args_list)
69 69
 
70
+    @mock.patch.object(commands.KayobeAnsibleMixin,
71
+                       "run_kayobe_playbook")
72
+    def test_physical_network_configure(self, mock_run):
73
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
74
+        parser = command.get_parser("test")
75
+        parsed_args = parser.parse_args(["--group", "switches"])
76
+        result = command.run(parsed_args)
77
+        self.assertEqual(0, result)
78
+        expected_calls = [
79
+            mock.call(
80
+                mock.ANY,
81
+                "ansible/physical-network.yml",
82
+                limit="switches",
83
+                extra_vars={
84
+                    "physical_network_display": False
85
+                }
86
+            )
87
+        ]
88
+        self.assertEqual(expected_calls, mock_run.call_args_list)
89
+
90
+    @mock.patch.object(commands.KayobeAnsibleMixin,
91
+                       "run_kayobe_playbook")
92
+    def test_physical_network_configure_display(self, mock_run):
93
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
94
+        parser = command.get_parser("test")
95
+        parsed_args = parser.parse_args(["--group", "switches", "--display"])
96
+        result = command.run(parsed_args)
97
+        self.assertEqual(0, result)
98
+        expected_calls = [
99
+            mock.call(
100
+                mock.ANY,
101
+                "ansible/physical-network.yml",
102
+                limit="switches",
103
+                extra_vars={
104
+                    "physical_network_display": True
105
+                }
106
+            )
107
+        ]
108
+        self.assertEqual(expected_calls, mock_run.call_args_list)
109
+
110
+    @mock.patch.object(commands.KayobeAnsibleMixin,
111
+                       "run_kayobe_playbook")
112
+    def test_physical_network_configure_enable_disco(self, mock_run):
113
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
114
+        parser = command.get_parser("test")
115
+        parsed_args = parser.parse_args(
116
+            ["--group", "switches", "--enable-discovery"])
117
+        result = command.run(parsed_args)
118
+        self.assertEqual(0, result)
119
+        expected_calls = [
120
+            mock.call(
121
+                mock.ANY,
122
+                "ansible/physical-network.yml",
123
+                limit="switches",
124
+                extra_vars={
125
+                    "physical_network_display": False,
126
+                    "physical_network_enable_discovery": True
127
+                }
128
+            )
129
+        ]
130
+        self.assertEqual(expected_calls, mock_run.call_args_list)
131
+
132
+    @mock.patch.object(commands.KayobeAnsibleMixin,
133
+                       "run_kayobe_playbook")
134
+    def test_physical_network_configure_disable_disco(self, mock_run):
135
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
136
+        parser = command.get_parser("test")
137
+        parsed_args = parser.parse_args(
138
+            ["--group", "switches", "--disable-discovery"])
139
+        result = command.run(parsed_args)
140
+        self.assertEqual(0, result)
141
+        expected_calls = [
142
+            mock.call(
143
+                mock.ANY,
144
+                "ansible/physical-network.yml",
145
+                limit="switches",
146
+                extra_vars={
147
+                    "physical_network_display": False,
148
+                    "physical_network_disable_discovery": True
149
+                }
150
+            )
151
+        ]
152
+        self.assertEqual(expected_calls, mock_run.call_args_list)
153
+
154
+    def test_physical_network_configure_enable_disable_disco(self):
155
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
156
+        parser = command.get_parser("test")
157
+        self.assertRaises(
158
+            SystemExit,
159
+            parser.parse_args,
160
+            ["--group", "switches", "--enable-discovery",
161
+             "--disable-discovery"])
162
+
163
+    @mock.patch.object(commands.KayobeAnsibleMixin,
164
+                       "run_kayobe_playbook")
165
+    def test_physical_network_configure_interface_limit(self, mock_run):
166
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
167
+        parser = command.get_parser("test")
168
+        parsed_args = parser.parse_args(
169
+            ["--group", "switches", "--interface-limit", "eth0,eth1"])
170
+        result = command.run(parsed_args)
171
+        self.assertEqual(0, result)
172
+        expected_calls = [
173
+            mock.call(
174
+                mock.ANY,
175
+                "ansible/physical-network.yml",
176
+                limit="switches",
177
+                extra_vars={
178
+                    "physical_network_display": False,
179
+                    "physical_network_interface_limit": "eth0,eth1"
180
+                }
181
+            )
182
+        ]
183
+        self.assertEqual(expected_calls, mock_run.call_args_list)
184
+
185
+    @mock.patch.object(commands.KayobeAnsibleMixin,
186
+                       "run_kayobe_playbook")
187
+    def test_physical_network_configure_interface_description_limit(
188
+            self, mock_run):
189
+        command = commands.PhysicalNetworkConfigure(TestApp(), [])
190
+        parser = command.get_parser("test")
191
+        parsed_args = parser.parse_args(
192
+            ["--group", "switches",
193
+             "--interface-description-limit", "host1,host2"])
194
+        result = command.run(parsed_args)
195
+        self.assertEqual(0, result)
196
+        expected_calls = [
197
+            mock.call(
198
+                mock.ANY,
199
+                "ansible/physical-network.yml",
200
+                limit="switches",
201
+                extra_vars={
202
+                    "physical_network_display": False,
203
+                    "physical_network_interface_description_limit": (
204
+                        "host1,host2")
205
+                }
206
+            )
207
+        ]
208
+        self.assertEqual(expected_calls, mock_run.call_args_list)
209
+
70 210
     @mock.patch.object(commands.KayobeAnsibleMixin,
71 211
                        "run_kayobe_playbooks")
72 212
     def test_network_connectivity_check(self, mock_run):

+ 14
- 0
releasenotes/notes/physical-network-disable-discovery-15916760e0a4d0bc.yaml View File

@@ -0,0 +1,14 @@
1
+---
2
+features:
3
+  - |
4
+    Adds support for a ``--disable-discovery`` argument to the ``kayobe
5
+    physical network configure`` command. This can be used to configure the
6
+    physical network after discovery of bare metal compute nodes is complete,
7
+    to return the network to a normal state. The interface configuration to be
8
+    applied is configured via ``switch_interface_config_disable_discovery``.
9
+deprecations:
10
+  - |
11
+    The switch configuration variable ``switch_interface_config_discovery`` has
12
+    been deprecated in favour of ``switch_interface_config_enable_discovery``.
13
+    Support for ``switch_interface_config_discovery`` will be removed in the T*
14
+    release.

Loading…
Cancel
Save