Fix introspection data lookup

Accessing ironic-introspection data from swift doesn't work with
utils.get_swift_client. This fix uses an auth session object and
swiftclient's Connection class instead.

Change-Id: Ie8c6cccb8fd9debf288cc449647dff5225f09e3e
This commit is contained in:
Florian Fuchs 2019-01-16 16:52:22 +00:00
parent a6246011d3
commit 3b54eea329
4 changed files with 72 additions and 42 deletions

View File

@ -9,6 +9,7 @@ python-novaclient>=9.1.0 # Apache-2.0
python-heatclient>=1.10.0 # Apache-2.0 python-heatclient>=1.10.0 # Apache-2.0
python-glanceclient>=2.9.1 # Apache-2.0 python-glanceclient>=2.9.1 # Apache-2.0
python-ironicclient>=2.3.0 # Apache-2.0 python-ironicclient>=2.3.0 # Apache-2.0
python-ironic-inspector-client>=3.1.1 # Apache-2.0
os-net-config>=7.1.0 # Apache-2.0 os-net-config>=7.1.0 # Apache-2.0
six>=1.10.0 # MIT six>=1.10.0 # MIT
tripleo-common>=7.1.0 # Apache-2.0 tripleo-common>=7.1.0 # Apache-2.0

View File

@ -24,28 +24,47 @@ class TestSwitchVlans(base.TestCase):
super(TestSwitchVlans, self).__init__(display) super(TestSwitchVlans, self).__init__(display)
self.introspect_data = { self.introspect_data = {
u'inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d': "inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d": {
'{"all_interfaces":' "all_interfaces": {
'{"em1": {"mac": "00:11:22:33:44:55",' "em1": {
'"lldp_processed": { "switch_port_id": "555",' "mac": "00:11:22:33:44:55",
'"switch_port_vlans":' "lldp_processed": {
'[{"id": 101, "name": "vlan101"},' "switch_port_id": "555",
'{"id": 104, "name": "vlan104"},' "switch_port_vlans": [
'{"id": 203, "name": "vlan203"}]}},' {"id": 101, "name": "vlan101"},
'"em2": {"mac": "00:11:22:33:44:66",' {"id": 104, "name": "vlan104"},
'"lldp_processed": { "switch_port_id": "557",' {"id": 203, "name": "vlan203"}
'"switch_port_vlans":' ]
'[{"id": 101, "name": "vlan101"},' }
'{"id": 105, "name": "vlan105"},' },
'{"id": 204, "name": "vlan204"}]}}}}', "em2": {
u'inspector_data-c0d2568e-1825-4d34-96ec-f08bbf0ba7ae': "mac": "00:11:22:33:44:66",
'{"all_interfaces":' "lldp_processed": {
'{"em1":{"mac": "00:66:77:88:99:aa",' "switch_port_id": "557",
'"lldp_processed": { "switch_port_id": "559",' "switch_port_vlans": [
'"switch_port_vlans":' {"id": 101, "name": "vlan101"},
'[{"id": 101, "name": "vlan101"},' {"id": 105, "name": "vlan105"},
'{"id": 201, "name": "vlan201"},' {"id": 204, "name": "vlan204"}
'{"id": 222, "name": "vlan222"}]}}}}' ]
}
}
}
},
"inspector_data-c0d2568e-1825-4d34-96ec-f08bbf0ba7ae": {
"all_interfaces": {
"em1": {
"mac": "00:66:77:88:99:aa",
"lldp_processed": {
"switch_port_id": "559",
"switch_port_vlans": [
{"id": 101, "name": "vlan101"},
{"id": 201, "name": "vlan201"},
{"id": 222, "name": "vlan222"}
]
}
}
}
}
} }
def test_valid_vlan_first_node(self): def test_valid_vlan_first_node(self):
@ -73,10 +92,15 @@ class TestSwitchVlans(base.TestCase):
self.assertEqual(msg, []) self.assertEqual(msg, [])
def test_no_lldp_data(self): def test_no_lldp_data(self):
local_data = {u'inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d': local_data = {
'{"all_interfaces":' "inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d": {
'{"em1": {"mac": "00:11:22:33:44:55"}}}' "all_interfaces": {
} "em1": {
"mac": "00:11:22:33:44:55"
}
}
}
}
msg, result = validation.vlan_exists_on_switch( msg, result = validation.vlan_exists_on_switch(
104, local_data) 104, local_data)

View File

@ -171,12 +171,8 @@ def vlan_exists_on_switch(vlan_id, introspection_data):
result: boolean indicating if VLAN was found result: boolean indicating if VLAN was found
""" """
for node, content in introspection_data.items(): for node, data in introspection_data.items():
node_valid_lldp = False node_valid_lldp = False
try:
data = yaml.safe_load(content)
except Exception as e:
return ["Can't open introspection data : {}" .format(e)], False
all_interfaces = data.get('all_interfaces', []) all_interfaces = data.get('all_interfaces', [])
@ -211,7 +207,7 @@ def main():
netenv_path = module.params.get('path') netenv_path = module.params.get('path')
template_files = {name: content[1] for (name, content) in template_files = {name: content[1] for (name, content) in
module.params.get('template_files')} module.params.get('template_files')}
introspection_data = {name: content[1] for (name, content) in introspection_data = {name: content for (name, content) in
module.params.get('introspection_data')} module.params.get('introspection_data')}
warnings, errors = validate_switch_vlans(netenv_path, template_files, warnings, errors = validate_switch_vlans(netenv_path, template_files,

View File

@ -16,8 +16,11 @@
# under the License. # under the License.
from ansible.plugins.lookup import LookupBase from ansible.plugins.lookup import LookupBase
from ironic_inspector_client import ClientError
from ironic_inspector_client import ClientV1
from ironicclient import client
from tripleo_validations import utils from tripleo_validations.utils import get_auth_session
class LookupModule(LookupBase): class LookupModule(LookupBase):
@ -29,15 +32,21 @@ class LookupModule(LookupBase):
:returns a list of tuples, one for each node. :returns a list of tuples, one for each node.
""" """
session = get_auth_session({
'auth_url': kwargs.get('auth_url'),
'password': kwargs.get('password'),
'username': 'ironic',
'project_name': 'service',
})
ironic = client.get_client(1, session=session)
ironic_inspector = ClientV1(session=session)
ret = [] ret = []
for node in ironic.node.list():
swift = utils.get_swift_client(variables) try:
container = swift.get_container("ironic-inspector") ret.append((node.name, ironic_inspector.get_data(node.uuid)))
except ClientError:
for item in container[1]: pass
if item['name'].startswith('inspector_data') and \
not item['name'].endswith("UNPROCESSED"):
obj = swift.get_object("ironic-inspector", item['name'])
ret.append((item['name'], obj))
return ret return ret