Browse Source

Adding API Trunk stub

Support for each provider should be added one at a time after this
patch. This patch just lays the framework for providers to be enabled.

Change-Id: I958520584f1784fa49d82778d004dced00b8a0c6
(cherry picked from commit 2969496314)
changes/89/679089/2
Dan Radez 9 months ago
parent
commit
b517c9b18b

+ 4
- 0
doc/source/contributor/provider.rst View File

@@ -39,6 +39,10 @@ networking-ansible.
39 39
 
40 40
   Defines the Ansible tasks to assign a VLAN to a switchport in access mode.
41 41
 
42
+* conf_trunk_port.yaml
43
+
44
+  Defines the Ansible tasks to configure a switchport in trunk mode.
45
+
42 46
 * delete_port.yaml
43 47
 
44 48
   Defines the Ansible tasks to remove configuration from a switchport.

+ 2
- 2
etc/ansible/roles/openstack-ml2/defaults/main.yml View File

@@ -1,6 +1,6 @@
1 1
 ---
2
-# defaults file for openstack-ml2
3
-#
2
+# params to impliment trunking
3
+trunked_vlans: "{{ trunked_vlans }}"
4 4
 
5 5
 # params to implement ml2 network resource
6 6
 #

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/cumulus/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for cumulus

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/eos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for eos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/junos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for junos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/nxos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for nxos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/openvswitch/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for openvswitch

+ 19
- 0
etc/ansible/roles/openstack-ml2/tasks/conf_trunk_port.yaml View File

@@ -0,0 +1,19 @@
1
+---
2
+# delegate task to localhost to avoid starting the device connection
3
+- name: "check for required fact: port"
4
+  fail:
5
+    msg: "missing required fact: port"
6
+  when: not port
7
+  delegate_to: localhost
8
+
9
+# delegate task to localhost to avoid starting the device connection
10
+- name: "check for required fact: port_description"
11
+  fail:
12
+    msg: "missing required fact: port_description"
13
+  when: not port_description
14
+  delegate_to: localhost
15
+
16
+- name: include and run device provider specific tasks
17
+  include_tasks: run.yaml
18
+  vars:
19
+    network_action: conf_trunk_port

+ 3
- 0
etc/ansible/roles/openstack-ml2/vars/main.yml View File

@@ -7,6 +7,9 @@ _delay: 7
7 7
 segmentation_id: null
8 8
 segmentation_name: null
9 9
 
10
+# vars optional for managing trunk ports
11
+vlans: null
12
+
10 13
 # vars required for managing ML2 ports
11 14
 port_name: null
12 15
 port_description: null

+ 25
- 2
networking_ansible/ansible_networking.py View File

@@ -37,13 +37,16 @@ class AnsibleNetworking(object):
37 37
             h['mac'].upper(): name for name, h in hosts.items() if 'mac' in h
38 38
         }
39 39
 
40
-    def _run_task(self, task, host_name, segmentation_id, switch_port=None):
40
+    def _run_task(self, task, host_name, segmentation_id,
41
+                  switch_port=None, trunked_vlans=None):
41 42
         """Run a task.
42 43
 
43 44
         :param task: name of task in openstack-ml2 ansible role
44 45
         :param host_name: name of a host defined in ml2 conf ini files
45
-        :param segmentation_id: vlan id of the network
46
+        :param segmentation_id: vlan id of the network,
47
+                                default VLAN for trunk ports
46 48
         :param switch_port: port name on the switch (optional)
49
+        :param trunked_vlans: A list of VLAN's for trunk port configuration
47 50
 
48 51
         See etc/ansible/roles/openstack-ml2/README.md for an exmaple playbook
49 52
         """
@@ -55,6 +58,8 @@ class AnsibleNetworking(object):
55 58
         else:
56 59
             segmentation_name = 'vlan{}'.format(segmentation_id)
57 60
 
61
+        trunked_vlans = trunked_vlans or []
62
+
58 63
         # build out the ansible playbook
59 64
         playbook = [{
60 65
             'name': 'Openstack networking-ansible playbook',
@@ -72,6 +77,8 @@ class AnsibleNetworking(object):
72 77
                 }
73 78
             }]
74 79
         }]
80
+        if trunked_vlans:
81
+            playbook[0]['tasks'][0]['vars']['trunked_vlans'] = trunked_vlans
75 82
         if switch_port:
76 83
             playbook[0]['tasks'][0]['vars']['port_name'] = switch_port
77 84
             playbook[0]['tasks'][0]['vars']['port_description'] = switch_port
@@ -151,3 +158,19 @@ class AnsibleNetworking(object):
151 158
                 switch_name=switch_name,
152 159
                 exc=e))
153 160
             raise
161
+
162
+    def conf_trunk_port(self, hostname, port, vlan_id, trunked_vlans):
163
+        """Configure trunk port w/ default vlan and optional additional vlans
164
+
165
+        :param hostname: The name of the host in Ansible inventory.
166
+        :param port: The port to configure.
167
+        :param vlan_id: the default VLAN ID to assign to the port
168
+                        An empty or None value will default to the
169
+                        target device's default VLAN assignment. This
170
+                        default is assigned in the ansible role.
171
+        :param trunked_vlans: A list of VLAN IDs to add to the port in
172
+                              addition to the default VLAN.
173
+        """
174
+        return self._run_task('conf_trunk_port',
175
+                              hostname, port, vlan_id,
176
+                              trunked_vlans=trunked_vlans)

+ 1
- 0
networking_ansible/tests/unit/base.py View File

@@ -51,6 +51,7 @@ class NetworkingAnsibleTestCase(test_plugin.Ml2PluginV2TestCase):
51 51
             self.mech = mech_driver.AnsibleMechanismDriver()
52 52
             self.mech.initialize()
53 53
         self.testsegid = '37'
54
+        self.testsegids = [73, 7, 3]
54 55
         self.testport = 'switchportid'
55 56
         self.empty_inventory = {'all': {'hosts': {}}}
56 57
 

+ 27
- 0
networking_ansible/tests/unit/test_ansible_networking.py View File

@@ -148,3 +148,30 @@ class TestVlanAccessPort(base.NetworkingAnsibleTestCase):
148 148
                           'remove',
149 149
                           self.mock_port_context.current,
150 150
                           self.mock_net_context.current)
151
+
152
+
153
+@mock.patch('networking_ansible.ansible_networking'
154
+            '.AnsibleNetworking._run_task')
155
+class TestConfTrunkPort(base.NetworkingAnsibleTestCase):
156
+
157
+    def test_assign_trunk_port(self, m_run_task):
158
+        self.mech.ansnet.conf_trunk_port(self.testhost,
159
+                                         self.testport,
160
+                                         self.testsegid,
161
+                                         trunked_vlans=self.testsegids)
162
+
163
+        m_run_task.assert_called_once()
164
+
165
+    def test_remove_trunk_port(self, m_run_task):
166
+        self.mech.ansnet.vlan_access_port('remove',
167
+                                          self.mock_port_context.current,
168
+                                          self.mock_net_context.current)
169
+
170
+        m_run_task.assert_called_once()
171
+
172
+    def test_remove_trunk_port_raises(self, m_run_task):
173
+        m_run_task.side_effect = exceptions.AnsibleRunnerException('test')
174
+        self.assertRaises(exceptions.AnsibleRunnerException,
175
+                          self.mech.ansnet.vlan_access_port, 'remove',
176
+                          self.mock_port_context.current,
177
+                          self.mock_net_context.current)

Loading…
Cancel
Save