Files
zaza-openstack-tests/zaza/openstack/charm_tests/neutron_arista/utils.py
T
Alex Kavanagh 0af4c93d52 Switch unit.public_address to unit.get_public_address()
Due to the bug [1] on OpenStack providers, unit.public_address doesn't
actually work reliably.  The fix [2] is only for the async function
unit.get_public_address().  Sadly, zaza relied on unit.public_address
and so it needs this patch for juju 2.9 support on OpenStack providers.

This patch relies on an associated patch in zaza [3]; thus this will
fails its tests until that passes.

[1]: https://github.com/juju/python-libjuju/issues/551
[2]: https://github.com/juju/python-libjuju/pull/600
[3]: https://github.com/openstack-charmers/zaza/pull/468
2022-01-14 15:21:32 +00:00

70 lines
2.1 KiB
Python

# Copyright 2020 Canonical Ltd.
#
# 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.
"""Common Arista-related utils."""
import json
import requests
import urllib3
import zaza
FIXTURE_APP_NAME = 'arista-virt-test-fixture'
PLUGIN_APP_NAME = 'neutron-api-plugin-arista'
def fixture_ip_addr():
"""Return the public IP address of the Arista test fixture."""
return zaza.model.get_unit_public_address(
zaza.model.get_units(FIXTURE_APP_NAME)[0])
_FIXTURE_LOGIN = 'admin'
_FIXTURE_PASSWORD = 'password123'
def query_fixture_networks(ip_addr):
"""Query the Arista test fixture's list of networks."""
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = requests.Session()
session.headers['Content-Type'] = 'application/json'
session.headers['Accept'] = 'application/json'
session.verify = False
session.auth = (_FIXTURE_LOGIN, _FIXTURE_PASSWORD)
data = {
'id': 'Zaza {} tests'.format(PLUGIN_APP_NAME),
'method': 'runCmds',
'jsonrpc': '2.0',
'params': {
'timestamps': False,
'format': 'json',
'version': 1,
'cmds': ['show openstack networks']
}
}
response = session.post(
'https://{}/command-api/'.format(ip_addr),
data=json.dumps(data),
timeout=10 # seconds
)
result = []
for region in response.json()['result'][0]['regions'].values():
for tenant in region['tenants'].values():
for network in tenant['tenantNetworks'].values():
result.append(network['networkName'])
return result