summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2018-10-11 19:27:51 +0100
committerMark Goddard <mark@stackhpc.com>2018-10-11 19:31:20 +0100
commite3e48e93ce2a7f6d7a4f76ee38d0017201821612 (patch)
tree33afe04f6e18c361802d104d69b482b74ad737d6
parentebf93b8dc187a9e4f40a5b1c0e0a58e13ab44006 (diff)
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
Notes
Notes (review): Code-Review+2: Doug Szumski <doug@stackhpc.com> Code-Review+2: Will Szumski <will@stackhpc.com> Workflow+1: Will Szumski <will@stackhpc.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 02 Nov 2018 17:44:42 +0000 Reviewed-on: https://review.openstack.org/609781 Project: openstack/kayobe Branch: refs/heads/master
-rw-r--r--ansible/group_vars/switches/config16
-rw-r--r--ansible/physical-network.yml13
-rw-r--r--kayobe/cli/commands.py11
-rw-r--r--kayobe/tests/unit/cli/test_commands.py140
-rw-r--r--releasenotes/notes/physical-network-disable-discovery-15916760e0a4d0bc.yaml14
5 files changed, 188 insertions, 6 deletions
diff --git a/ansible/group_vars/switches/config b/ansible/group_vars/switches/config
index 0099aa0..9ba165f 100644
--- a/ansible/group_vars/switches/config
+++ b/ansible/group_vars/switches/config
@@ -18,7 +18,19 @@ switch_config: []
18# file. 18# file.
19switch_interface_config: {} 19switch_interface_config: {}
20 20
21# Interface configuration for hardware discovery. After discovery Neutron owns 21# Interface configuration for enabling hardware discovery. After discovery
22# the configuration of these ports. Has the same format as 22# Neutron owns the configuration of these ports. Has the same format as
23# switch_interface_config. 23# switch_interface_config.
24# [DEPRECATED] Use switch_interface_config_enable_discovery.
24switch_interface_config_discovery: {} 25switch_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.
31switch_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.
36switch_interface_config_disable_discovery: {}
diff --git a/ansible/physical-network.yml b/ansible/physical-network.yml
index ddffab4..9235420 100644
--- a/ansible/physical-network.yml
+++ b/ansible/physical-network.yml
@@ -9,6 +9,9 @@
9 # Set this variable to True to configure the network for hardware 9 # Set this variable to True to configure the network for hardware
10 # discovery. 10 # discovery.
11 physical_network_enable_discovery: False 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 # Set this variable to a comma-separated list of names of interfaces to 15 # Set this variable to a comma-separated list of names of interfaces to
13 # configure in order to restrict configuration to a subset of interfaces. 16 # configure in order to restrict configuration to a subset of interfaces.
14 physical_network_interface_limit: '' 17 physical_network_interface_limit: ''
@@ -53,12 +56,18 @@
53 group_by: 56 group_by:
54 key: "switches_in_display_mode_{{ physical_network_display | bool }}" 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 set_fact: 60 set_fact:
58 switch_interface_config: > 61 switch_interface_config: >
59 {{ switch_interface_config | combine(switch_interface_config_discovery) }} 62 {{ switch_interface_config | combine(switch_interface_config_enable_discovery) }}
60 when: physical_network_enable_discovery | bool 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 - name: Restrict switch interfaces to requested subset by name 71 - name: Restrict switch interfaces to requested subset by name
63 set_fact: 72 set_fact:
64 switch_interface_config: > 73 switch_interface_config: >
diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py
index e858697..c44a0d1 100644
--- a/kayobe/cli/commands.py
+++ b/kayobe/cli/commands.py
@@ -228,14 +228,19 @@ class PhysicalNetworkConfigure(KayobeAnsibleMixin, VaultMixin, Command):
228 group.add_argument("--display", action="store_true", 228 group.add_argument("--display", action="store_true",
229 help="display the candidate configuration and exit " 229 help="display the candidate configuration and exit "
230 "without applying it") 230 "without applying it")
231 group.add_argument("--enable-discovery", action="store_true",
232 help="configure the network for hardware discovery")
233 group.add_argument("--interface-limit", 231 group.add_argument("--interface-limit",
234 help="limit the switch interfaces to be configured " 232 help="limit the switch interfaces to be configured "
235 "by interface name") 233 "by interface name")
236 group.add_argument("--interface-description-limit", 234 group.add_argument("--interface-description-limit",
237 help="limit the switch interfaces to be configured " 235 help="limit the switch interfaces to be configured "
238 "by interface description") 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 return parser 244 return parser
240 245
241 def take_action(self, parsed_args): 246 def take_action(self, parsed_args):
@@ -244,6 +249,8 @@ class PhysicalNetworkConfigure(KayobeAnsibleMixin, VaultMixin, Command):
244 extra_vars["physical_network_display"] = parsed_args.display 249 extra_vars["physical_network_display"] = parsed_args.display
245 if parsed_args.enable_discovery: 250 if parsed_args.enable_discovery:
246 extra_vars["physical_network_enable_discovery"] = True 251 extra_vars["physical_network_enable_discovery"] = True
252 if parsed_args.disable_discovery:
253 extra_vars["physical_network_disable_discovery"] = True
247 if parsed_args.interface_limit: 254 if parsed_args.interface_limit:
248 extra_vars["physical_network_interface_limit"] = ( 255 extra_vars["physical_network_interface_limit"] = (
249 parsed_args.interface_limit) 256 parsed_args.interface_limit)
diff --git a/kayobe/tests/unit/cli/test_commands.py b/kayobe/tests/unit/cli/test_commands.py
index 318ff4c..07748a7 100644
--- a/kayobe/tests/unit/cli/test_commands.py
+++ b/kayobe/tests/unit/cli/test_commands.py
@@ -68,6 +68,146 @@ class TestCase(unittest.TestCase):
68 self.assertEqual(expected_calls, mock_run.call_args_list) 68 self.assertEqual(expected_calls, mock_run.call_args_list)
69 69
70 @mock.patch.object(commands.KayobeAnsibleMixin, 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
210 @mock.patch.object(commands.KayobeAnsibleMixin,
71 "run_kayobe_playbooks") 211 "run_kayobe_playbooks")
72 def test_network_connectivity_check(self, mock_run): 212 def test_network_connectivity_check(self, mock_run):
73 command = commands.NetworkConnectivityCheck(TestApp(), []) 213 command = commands.NetworkConnectivityCheck(TestApp(), [])
diff --git a/releasenotes/notes/physical-network-disable-discovery-15916760e0a4d0bc.yaml b/releasenotes/notes/physical-network-disable-discovery-15916760e0a4d0bc.yaml
new file mode 100644
index 0000000..f26487a
--- /dev/null
+++ b/releasenotes/notes/physical-network-disable-discovery-15916760e0a4d0bc.yaml
@@ -0,0 +1,14 @@
1---
2features:
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``.
9deprecations:
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.