diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 4229110..a4f6def 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -15,8 +15,16 @@ def test_python_pip_packages_installed(host): assert apt_package_python3.is_installed assert apt_package_pip.is_installed +def test_pip_installed_latest(host): + """Validate pip is installed and up-to-date""" + pip_packages_list = host.pip.get_packages(pip_path='pip') + pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip') + assert 'pip' in pip_packages_list + assert 'pip' not in pip_outdated_list + def test_packages_not_installed(host): - """Validate vim is installed""" - pip_packages_list = host.pip_package.get_packages(pip_path='pip') - print(pip_packages_list) - assert True == False + """Validate docker, yamllint and vault-cli are not installed""" + pip_packages_list = host.pip.get_packages(pip_path='pip') + assert 'docker' not in pip_packages_list + assert 'yamllint' not in pip_packages_list + assert 'vault-cli' not in pip_packages_list diff --git a/molecule/with_custom_packages/tests/test_default.py b/molecule/with_custom_packages/tests/test_default.py index 99cf339..66165b2 100644 --- a/molecule/with_custom_packages/tests/test_default.py +++ b/molecule/with_custom_packages/tests/test_default.py @@ -1,5 +1,6 @@ """Role testing files using testinfra.""" -import json +from packaging import version + def test_hosts_file(host): """Validate /etc/hosts file.""" @@ -15,11 +16,22 @@ def test_python_pip_packages_installed(host): assert apt_package_python3.is_installed assert apt_package_pip.is_installed -def test_packages_not_installed(host): - """Validate vim is installed""" - pip_packages_list = host.pip_package.get_packages(pip_path='pip') - assert pip_packages_list['pip'] - assert pip_packages_list['docker'] - assert pip_packages_list['zeubi'] - print(pip_packages_list) +def test_pip_installed_latest(host): + """Validate pip is installed and up-to-date""" + pip_packages_list = host.pip.get_packages(pip_path='pip') + pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip') + assert 'pip' in pip_packages_list + assert 'pip' not in pip_outdated_list +def test_packages_installed(host): + """Validate docker, yamllint and vault-cli are installed""" + pip_packages_list = host.pip.get_packages(pip_path='pip') + pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip') + assert 'docker' in pip_packages_list + assert 'docker' not in pip_outdated_list + assert 'yamllint' in pip_packages_list + assert 'yamllint' in pip_outdated_list + assert version.parse(pip_packages_list['yamllint']['version']) == version.parse("1.24") + assert 'vault-cli' in pip_packages_list + assert 'vault-cli' in pip_outdated_list + assert version.parse(pip_packages_list['vault-cli']['version']) < version.parse("3.1.0") diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml index fac4de4..36ac285 100644 --- a/tasks/prerequisites.yml +++ b/tasks/prerequisites.yml @@ -11,3 +11,8 @@ - name: "{{ manage_pip_packages_pip3_package_name }}" version: latest state: present + +- name: "Update pip to latest" + ansible.builtin.pip: + name: pip + extra_args: --upgrade