Skip to content

Commit

Permalink
Merge pull request #628 from HewlettPackard/LIG_NetworkSet
Browse files Browse the repository at this point in the history
Issue 622
  • Loading branch information
AsisBagga committed Feb 8, 2021
2 parents 4dc4600 + 8c10107 commit 76099b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This release extends the planned support of the modules to OneView REST API vers
- [#612] (https://github.com/HewlettPackard/oneview-ansible/issues/612) FC network bandwidth
- [#614] (https://github.com/HewlettPackard/oneview-ansible/issues/614) Typo in oneview_server_profile_template_with_resource_name.yml
- [#620] (https://github.com/HewlettPackard/oneview-ansible/issues/620) git installed ansible oneview container image.
- [#622] (https://github.com/HewlettPackard/oneview-ansible/issues/622) Updating LIG with network set uri with mentioning networkset names.

### Modules supported in this release
- oneview_alert_facts
Expand Down
19 changes: 18 additions & 1 deletion library/oneview_logical_interconnect_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def __present(self):

def __replace_name_by_uris(self):
map_template = self.data.get('interconnectMapTemplate')

if map_template:
map_entry_templates = map_template.get('interconnectMapEntryTemplates')
if map_entry_templates:
Expand All @@ -201,11 +200,17 @@ def __uplink_set_update(self):
allUplinkSets = self.__get_all_uplink_sets()
for uplinkSet in self.data['uplinkSets']:
networkNames = uplinkSet.pop('networkNames', None)
networkSetNames = uplinkSet.pop('networkSetNames', None)
if networkNames and not uplinkSet.get('networkUris'):
uplinkSet['networkUris'] = []
if networkNames:
networkUris = [self.__get_network_uri(x) for x in networkNames]
uplinkSet['networkUris'].extend(networkUris)
if networkSetNames and not uplinkSet.get('networkSetUris'):
uplinkSet['networkSetUris'] = []
if networkSetNames:
networkSetUris = [self.__get_network_set(x) for x in networkSetNames]
uplinkSet['networkSetUris'].extend(networkSetUris)
allUplinkSets = self.__update_existing_uplink_set(allUplinkSets, uplinkSet)
self.data['uplinkSets'] = allUplinkSets
else:
Expand All @@ -214,11 +219,17 @@ def __uplink_set_update(self):
def __update_network_uri(self):
for i in range(len(self.data['uplinkSets'])):
networkNames = self.data['uplinkSets'][i].pop('networkNames', None)
networkSetNames = self.data['uplinkSets'][i].pop('networkSetNames', None)
if networkNames and not self.data['uplinkSets'][i].get('networkUris'):
self.data['uplinkSets'][i]['networkUris'] = []
if networkNames:
networkUris = [self.__get_network_uri(x) for x in networkNames]
self.data['uplinkSets'][i]['networkUris'].extend(networkUris)
if networkSetNames and not self.data['uplinkSets'][i].get('networkSetUris'):
self.data['uplinkSets'][i]['networkSetUris'] = []
if networkSetNames:
networkSetUris = [self.__get_network_set(x) for x in networkSetNames]
self.data['uplinkSets'][i]['networkSetUris'].extend(networkSetUris)

def __update_existing_uplink_set(self, allUplinkSets, newUplinkSet):
temp = True
Expand Down Expand Up @@ -250,6 +261,12 @@ def __get_network_uri(self, name):
return network_name[0]['uri']
return False

def __get_network_set(self, name):
network_set = self.oneview_client.network_sets.get_by('name', name)
if network_set:
return network_set[0]['uri']
return False

def __get_interconnect_type_by_name(self, name):
i_type = self.oneview_client.interconnect_types.get_by('name', name)
if i_type:
Expand Down
8 changes: 6 additions & 2 deletions test/test_oneview_logical_interconnect_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
name="EnetUplink1",
networkType="Ethernet",
networkNames=["TestNetwork_1"],
networkSetUris=["/rest/network-set/1234"]
networkSetNames=["test_1"]
)],
enclosureType='C7000',
interconnectMapTemplate=dict(
Expand Down Expand Up @@ -96,6 +96,7 @@
name="NewEnetUplink",
networkType="Ethernet",
networkNames=["TestNetwork_1"],
networkSetNames=["test_1"]
)],
enclosureType='C7000',
interconnectMapTemplate=dict(
Expand Down Expand Up @@ -130,7 +131,7 @@
name="EnetUplink1",
networkType="Ethernet",
networkNames=["TestNetwork_2"],
networkSetUris=["/rest/network-set/12345"]
networkSetNames=["test_2"]
)
],
enclosureType='C7000',
Expand Down Expand Up @@ -293,6 +294,7 @@ def test_should_create_new_lig_with_uplinkset(self):
self.resource.create.return_value = self.resource
self.mock_ov_client.logical_interconnect_groups.get_by.return_value = None
self.mock_ov_client.ethernet_networks.get_by.return_value = []
self.mock_ov_client.network_sets.get_by.return_value = []
self.mock_ansible_module.params = PARAMS_FOR_CREATE

LogicalInterconnectGroupModule().run()
Expand Down Expand Up @@ -361,6 +363,7 @@ def test_update_when_data_has_modified_uplinkset_attributes(self):
self.resource.data = DEFAULT_LIG_TEMPLATE_WITH_UPLINKSETS
self.mock_ov_client.logical_interconnect_groups.get_by.return_value = UPLINK_SETS
self.mock_ov_client.ethernet_networks.get_by.return_value = [dict(uri='/rest/ethernet-networks/18')]
self.mock_ov_client.network_sets.get_by.return_value = [dict(uri='/rest/network-sets/18')]
self.mock_ansible_module.params = DEFAULT_LIG_TEMPLATE_WITH_DIFFERENT_UPLINKSETS

LogicalInterconnectGroupModule().run()
Expand All @@ -375,6 +378,7 @@ def test_update_when_data_has_new_uplinkset(self):
self.resource.data = DEFAULT_LIG_TEMPLATE_WITH_NEW_UPLINKSETS
self.mock_ov_client.logical_interconnect_groups.get_by.return_value = UPLINK_SETS
self.mock_ov_client.ethernet_networks.get_by.return_value = [dict(uri='/rest/ethernet-networks/18')]
self.mock_ov_client.network_sets.get_by.return_value = [dict(uri='/rest/network-sets/18')]
self.mock_ansible_module.params = DEFAULT_LIG_TEMPLATE_WITH_NEW_UPLINKSETS

LogicalInterconnectGroupModule().run()
Expand Down

0 comments on commit 76099b7

Please sign in to comment.