Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_credentails() doesn't check if unit is None #368

Open
coreycb opened this issue Jul 16, 2020 · 1 comment
Open

get_credentails() doesn't check if unit is None #368

coreycb opened this issue Jul 16, 2020 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@coreycb
Copy link

coreycb commented Jul 16, 2020

Code with my own print debugs added:

def find_unit_with_creds():
    """Find the unit thats has stored the credentials.

    :returns: unit name
    :rtype: str
    """
    unit = None
    print("CCB: unit={}".format(unit))
    for vault_unit in zaza.model.get_units('vault'):
        print("CCB: vault_unit={}".format(vault_unit))
        cmd = 'ls -l ~ubuntu/{}'.format(AUTH_FILE)
        print("CCB: cmd={}".format(cmd))
        resp = zaza.model.run_on_unit(vault_unit.name, cmd)
        print("CCB: resp={}".format(resp))
        print("CCB: resp.get('Code')={}".format(resp.get('Code')))
        if resp.get('Code') == '0':
            unit = vault_unit.name
            break
    print("CCB: unit={}".format(unit))
    return unit

def get_credentails():
    """Retrieve vault token and keys from unit.

    Retrieve vault token and keys from unit. These are stored on a unit
    during functional tests.

    :returns: Tokens and keys for accessing test environment
    :rtype: dict
    """
    unit = find_unit_with_creds()
    print("CCB: unit={}".format(unit))
    with tempfile.TemporaryDirectory() as tmpdirname:
        tmp_file = '{}/{}'.format(tmpdirname, AUTH_FILE)
        zaza.model.scp_from_unit(
            unit,
            '~/{}'.format(AUTH_FILE),
            tmp_file)
        with open(tmp_file, 'r') as stream:
            creds = yaml.safe_load(stream)
    return creds

For some reason ~ubuntu/vault_tests.yaml doesn't exist on the vault/0 unit, resulting in unit = None.

Debug output:

(func-smoke) ubuntu@coreycb-bastion:~/charmed-openstack-tester/tests/distro-regression$ functest-configure -m keystone_v3_smoke_focal:zaza-8a8caa275a3d
2020-07-16 19:28:57 [INFO] Running auto_initialize
CCB: unit=None
CCB: vault_unit=
CCB: cmd=ls -l ~ubuntu/vault_tests.yaml
CCB: unit_name=vault/0
CCB: resp={'Code': '2', 'Stderr': "ls: cannot access '/home/ubuntu/vault_tests.yaml': No such file or directory\n", 'Stdout': ''}
CCB: resp.get('Code')=2
CCB: unit=None
CCB: unit=None
CCB: unit_name=None

This ends up with a traceback that is hard to diagnose:

Traceback (most recent call last):             
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/bin/functest-configure", line 8, in <module>                                                                                                                                                                        
    sys.exit(main())             
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/charm_lifecycle/configure.py", line 85, in main
    configure(model_name, funcs)                                                                                                         
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/charm_lifecycle/configure.py", line 48, in configure
    run_configure_list(functions)
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/charm_lifecycle/configure.py", line 37, in run_configure_list
    utils.get_class(func)()                       
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/openstack/charm_tests/vault/setup.py", line 119, in auto_initialize
    basic_setup(cacert=cacert, unseal_and_authorize=True)
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/openstack/charm_tests/vault/setup.py", line 57, in basic_setup
    vault_svc = vault_utils.VaultFacade(cacert=cacert)
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 63, in __init__
    self.initialize()                                         
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 73, in initialize
    self.vault_creds = get_credentails()                                                                                                 
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 282, in get_credentails
    tmp_file)                                                                                                                            
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/__init__.py", line 48, in _wrapper
    return run(_run_it())
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/__init__.py", line 36, in run
    return task.result()
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/__init__.py", line 47, in _run_it
    return await f(*args, **kwargs)     
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/model.py", line 266, in async_scp_from_unit
    unit = get_unit_from_name(unit_name, model)
  File "/home/ubuntu/charmed-openstack-tester/.tox/func-smoke/lib/python3.6/site-packages/zaza/model.py", line 145, in get_unit_from_name 
    app = unit_name.split('/')[0]
@rgildein
Copy link

I also encountered this issue.

(overcloud) ubuntu@rgildein-bastion:~/charm-openstack-integrator$ functest-configure --model openstack-overcloud -c zaza.openstack.charm_tests.vault.setup.auto_initialize
2022-06-13 11:21:30 [INFO] Running auto_initialize
CCB: unit=None
CCB: vault_unit=<Unit entity_id="vault/0">
CCB: cmd=ls -l ~ubuntu/vault_tests.yaml
CCB: resp={'Code': '2', 'Stderr': "ls: cannot access '/home/ubuntu/vault_tests.yaml': No such file or directory\n", 'Stdout': '', 'stderr': "ls: cannot access '/home/ubuntu/vault_tests.yaml': No such file or directory\n", 'stdout': ''}
CCB: resp.get('Code')=2
CCB: unit=None
CCB: unit=None
Traceback (most recent call last):
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/bin/functest-configure", line 8, in <module>
    sys.exit(main())
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/charm_lifecycle/configure.py", line 96, in main
    configure(model_name, funcs)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/charm_lifecycle/configure.py", line 58, in configure
    run_configure_list(functions)
  File "/usr/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/charm_lifecycle/configure.py", line 44, in run_configure_list
    utils.get_class(func)()
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/openstack/charm_tests/vault/setup.py", line 162, in auto_initialize
    basic_setup(cacert=cacert, unseal_and_authorize=True)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/openstack/charm_tests/vault/setup.py", line 56, in basic_setup
    vault_svc = vault_utils.VaultFacade(cacert=cacert)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 65, in __init__
    self.initialize()
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 75, in initialize
    self.vault_creds = get_credentials()
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/openstack/charm_tests/vault/utils.py", line 317, in get_credentials
    zaza.model.scp_from_unit(
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/__init__.py", line 108, in _wrapper
    return run(_run_it())
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/__init__.py", line 93, in run
    return task.result()
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/__init__.py", line 107, in _run_it
    return await f(*args, **kwargs)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/model.py", line 397, in async_scp_from_unit
    unit = get_unit_from_name(unit_name, model)
  File "/home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages/zaza/model.py", line 172, in get_unit_from_name
    app = unit_name.split('/')[0]
AttributeError: 'NoneType' object has no attribute 'split'
(overcloud) 1 ubuntu@rgildein-bastion:~/charm-openstack-integrator$ python --version
Python 3.8.10
(overcloud) ubuntu@rgildein-bastion:~/charm-openstack-integrator$ pip show zaza
Name: zaza
Version: 0.0.2.dev1
Summary: A Python3-only functional test framework for OpenStack Charms
Home-page: https://github.com/openstack-charmers/zaza
Author: OpenStack Charmers
Author-email: [email protected]
License: Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
Location: /home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages
Requires: PyYAML, jinja2, oslo.config, python-libmaas, tenacity, juju-wait, juju, async-generator, hvac, cryptography
Required-by: zaza.openstack
(overcloud) ubuntu@rgildein-bastion:~/charm-openstack-integrator$ pip show zaza-openstack
Name: zaza.openstack
Version: 0.0.1.dev1
Summary: Zaza tests for the OpenStack Charms project
Home-page: https://github.com/openstack-charmers/zaza-openstack-tests
Author: OpenStack Charmers
Author-email: [email protected]
License: Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
Location: /home/ubuntu/charm-openstack-integrator/.tox/overcloud/lib/python3.8/site-packages
Requires: tenacity, python-octaviaclient, python-neutronclient, gnocchiclient, python-designateclient, python-keystoneclient, dnspython, juju, cryptography, aodhclient, python-novaclient, python-ceilometerclient, boto3, python-heatclient, pyparsing, python-cinderclient, oslo.config, juju-wait, async-generator, jinja2, python-swiftclient, hvac, PyYAML, python-manilaclient, futurist, python-ironicclient, python-glanceclient, python-barbicanclient, lxml, pika, zaza
Required-by:

@ajkavanagh ajkavanagh added bug Something isn't working good first issue Good for newcomers labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants