# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest.mock import Mock
import drydock_provisioner.objects as objects
class TestClass(object):
def test_apply_logicalnames_else(self, input_files, deckhand_orchestrator,
drydock_state, mock_get_build_data):
"""Test node apply_logicalnames hits the else block"""
input_file = input_files.join("deckhand_fullsite.yaml")
design_ref = "file://%s" % str(input_file)
design_status, design_data = deckhand_orchestrator.get_effective_site(
design_ref)
def side_effect(**kwargs):
return []
drydock_state.get_build_data = Mock(side_effect=side_effect)
nodes = design_data.baremetal_nodes
for n in nodes or []:
n.apply_logicalnames(design_data, state_manager=drydock_state)
assert n.logicalnames == {}
def test_apply_logicalnames_success(self, input_files,
deckhand_orchestrator, drydock_state,
mock_get_build_data):
"""Test node apply_logicalnames to get the proper dictionary"""
input_file = input_files.join("deckhand_fullsite.yaml")
design_ref = "file://%s" % str(input_file)
xml_example = """
Rack Mount Chassis
PowerEdge R720xd (SKU=NotProvided;ModelName=PowerEdge R720xd)
Dell Inc.
6H5LBY1
64
SMBIOS version 2.7
DMI version 2.7
32-bit processes
PCI bridge
Xeon E5/Core i7 IIO PCI Express Root Port 2a
Intel Corporation
2
pci@0000:00:02.0
07
32
33000000
Message Signalled Interrupts
PCI Express
Power Management
bus mastering
PCI capabilities listing
Ethernet interface
I350 Gigabit Network Connection
Intel Corporation
0
pci@0000:00:03.0
eno1
01
b8:ca:3a:65:7d:d8
1000000000
1000000000
32
33000000
SCSI Disk
PERC H710P
DELL
2.0.0
scsi@2:0.0.0
/dev/sda
8:0
3.13
0044016c12771be71900034cfba0a38c
299439751168
"""
xml_example = xml_example.replace('\n', '')
def side_effect(**kwargs):
build_data = objects.BuildData(node_name="controller01",
task_id="tid",
generator="lshw",
data_format="text/plain",
data_element=xml_example)
return [build_data]
drydock_state.get_build_data = Mock(side_effect=side_effect)
design_status, design_data = deckhand_orchestrator.get_effective_site(
design_ref, resolve_aliases=True)
nodes = design_data.baremetal_nodes
expected = {
'primary_boot': 'sda',
'prim_nic02': 'prim_nic02',
'prim_nic01': 'eno1'
}
# Tests the whole dictionary
assert nodes[0].logicalnames == expected
# Makes sure the path and / are both removed from primary_boot
assert nodes[0].logicalnames['primary_boot'] == 'sda'
assert nodes[0].get_logicalname('primary_boot') == 'sda'
# A simple logicalname
assert nodes[0].logicalnames['prim_nic01'] == 'eno1'
assert nodes[0].get_logicalname('prim_nic01') == 'eno1'
# Logicalname is not found, returns the alias
assert nodes[0].logicalnames['prim_nic02'] == 'prim_nic02'
assert nodes[0].get_logicalname('prim_nic02') == 'prim_nic02'
def test_apply_logicalnames_nic_autodetect_success(self, input_files,
deckhand_orchestrator,
drydock_state,
mock_get_build_data):
"""Test node apply_logicalnames to get the proper dictionary"""
input_file = input_files.join("deckhand_fullsite_nic_autodetect.yaml")
design_ref = "file://%s" % str(input_file)
xml_example = """
Rack Mount Chassis
PowerEdge R720xd (SKU=NotProvided;ModelName=PowerEdge R720xd)
Dell Inc.
6H5LBY1
64
SMBIOS version 2.7
DMI version 2.7
32-bit processes
PCI bridge
Xeon E5/Core i7 IIO PCI Express Root Port 2a
Intel Corporation
2
pci@0000:00:02.0
07
32
33000000
Message Signalled Interrupts
PCI Express
Power Management
bus mastering
PCI capabilities listing
Ethernet interface
NetXtreme BCM5720 Gigabit Ethernet PCIe
Broadcom Inc. and subsidiaries
0
pci@0000:19:00.0
eno3
00
f0:d4:e2:e5:35:8e
1000000000
64
33000000
Ethernet interface
I350 Gigabit Network Connection
Intel Corporation
0.1
pci@0000:01:00.0
eno4
01
e4:43:4b:4d:d3:e7
1000000000
1000000000
32
33000000
SCSI Disk
PERC H710P
DELL
2.0.0
scsi@2:0.0.0
/dev/sda
8:0
3.13
0044016c12771be71900034cfba0a38c
299439751168
"""
xml_example = xml_example.replace('\n', '')
def side_effect(**kwargs):
build_data = objects.BuildData(node_name="controller01",
task_id="tid",
generator="lshw",
data_format="text/plain",
data_element=xml_example)
return [build_data]
drydock_state.get_build_data = Mock(side_effect=side_effect)
design_status, design_data = deckhand_orchestrator.get_effective_site(
design_ref, resolve_aliases=True)
nodes = design_data.baremetal_nodes
expected = {
'primary_boot': 'sda',
'prim_nic03': 'prim_nic03',
'prim_nic02': 'eno4',
'prim_nic01': 'eno3'
}
# Tests the whole dictionary
assert nodes[0].logicalnames == expected
# Makes sure the path and / are both removed from primary_boot
assert nodes[0].logicalnames['primary_boot'] == 'sda'
assert nodes[0].get_logicalname('primary_boot') == 'sda'
# A simple logicalname
assert nodes[0].logicalnames['prim_nic01'] == 'eno3'
assert nodes[0].get_logicalname('prim_nic01') == 'eno3'
assert nodes[0].logicalnames['prim_nic02'] == 'eno4'
assert nodes[0].get_logicalname('prim_nic02') == 'eno4'
# Logicalname is not found, returns the alias
assert nodes[0].logicalnames['prim_nic03'] == 'prim_nic03'
assert nodes[0].get_logicalname('prim_nic03') == 'prim_nic03'