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:
parent
a6246011d3
commit
3b54eea329
|
@ -9,6 +9,7 @@ python-novaclient>=9.1.0 # Apache-2.0
|
|||
python-heatclient>=1.10.0 # Apache-2.0
|
||||
python-glanceclient>=2.9.1 # 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
|
||||
six>=1.10.0 # MIT
|
||||
tripleo-common>=7.1.0 # Apache-2.0
|
||||
|
|
|
@ -24,28 +24,47 @@ class TestSwitchVlans(base.TestCase):
|
|||
super(TestSwitchVlans, self).__init__(display)
|
||||
|
||||
self.introspect_data = {
|
||||
u'inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d':
|
||||
'{"all_interfaces":'
|
||||
'{"em1": {"mac": "00:11:22:33:44:55",'
|
||||
'"lldp_processed": { "switch_port_id": "555",'
|
||||
'"switch_port_vlans":'
|
||||
'[{"id": 101, "name": "vlan101"},'
|
||||
'{"id": 104, "name": "vlan104"},'
|
||||
'{"id": 203, "name": "vlan203"}]}},'
|
||||
'"em2": {"mac": "00:11:22:33:44:66",'
|
||||
'"lldp_processed": { "switch_port_id": "557",'
|
||||
'"switch_port_vlans":'
|
||||
'[{"id": 101, "name": "vlan101"},'
|
||||
'{"id": 105, "name": "vlan105"},'
|
||||
'{"id": 204, "name": "vlan204"}]}}}}',
|
||||
u'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"}]}}}}'
|
||||
"inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d": {
|
||||
"all_interfaces": {
|
||||
"em1": {
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"lldp_processed": {
|
||||
"switch_port_id": "555",
|
||||
"switch_port_vlans": [
|
||||
{"id": 101, "name": "vlan101"},
|
||||
{"id": 104, "name": "vlan104"},
|
||||
{"id": 203, "name": "vlan203"}
|
||||
]
|
||||
}
|
||||
},
|
||||
"em2": {
|
||||
"mac": "00:11:22:33:44:66",
|
||||
"lldp_processed": {
|
||||
"switch_port_id": "557",
|
||||
"switch_port_vlans": [
|
||||
{"id": 101, "name": "vlan101"},
|
||||
{"id": 105, "name": "vlan105"},
|
||||
{"id": 204, "name": "vlan204"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"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):
|
||||
|
@ -73,10 +92,15 @@ class TestSwitchVlans(base.TestCase):
|
|||
self.assertEqual(msg, [])
|
||||
|
||||
def test_no_lldp_data(self):
|
||||
local_data = {u'inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d':
|
||||
'{"all_interfaces":'
|
||||
'{"em1": {"mac": "00:11:22:33:44:55"}}}'
|
||||
}
|
||||
local_data = {
|
||||
"inspector_data-8c3faec8-bc05-401c-8956-99c40cdea97d": {
|
||||
"all_interfaces": {
|
||||
"em1": {
|
||||
"mac": "00:11:22:33:44:55"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg, result = validation.vlan_exists_on_switch(
|
||||
104, local_data)
|
||||
|
|
|
@ -171,12 +171,8 @@ def vlan_exists_on_switch(vlan_id, introspection_data):
|
|||
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
|
||||
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', [])
|
||||
|
||||
|
@ -211,7 +207,7 @@ def main():
|
|||
netenv_path = module.params.get('path')
|
||||
template_files = {name: content[1] for (name, content) in
|
||||
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')}
|
||||
|
||||
warnings, errors = validate_switch_vlans(netenv_path, template_files,
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
# under the License.
|
||||
|
||||
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):
|
||||
|
@ -29,15 +32,21 @@ class LookupModule(LookupBase):
|
|||
|
||||
: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 = []
|
||||
|
||||
swift = utils.get_swift_client(variables)
|
||||
container = swift.get_container("ironic-inspector")
|
||||
|
||||
for item in container[1]:
|
||||
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))
|
||||
for node in ironic.node.list():
|
||||
try:
|
||||
ret.append((node.name, ironic_inspector.get_data(node.uuid)))
|
||||
except ClientError:
|
||||
pass
|
||||
|
||||
return ret
|
||||
|
|
Loading…
Reference in New Issue