Skip to content

Commit

Permalink
Merge branch 'master' into issues/545
Browse files Browse the repository at this point in the history
  • Loading branch information
freyes committed Oct 5, 2023
2 parents 7a5dba6 + 44333de commit 2b33642
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 42 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Lint with tox
run: tox -e pep8
- name: Test with tox
run: tox -e py
run: tox -e py3
- name: Codecov
run: |
set -euxo pipefail
Expand Down Expand Up @@ -96,3 +96,6 @@ jobs:
with:
name: test-run-logs-and-crashdump
path: logs/
- name: consider debugging
uses: lhotari/action-upterm@v1
if: failure()
15 changes: 15 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.10"

# Build from the docs/ directory with Sphinx
sphinx:
configuration: doc/source/conf.py

# Explicitly set the version of Python and its requirements
python:
install:
- requirements: docs-requirements.txt
5 changes: 5 additions & 0 deletions doc-requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
oslo.config
async_generator
juju<3.0
sphinx
sphinxcontrib-asyncio
168 changes: 168 additions & 0 deletions doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile doc-requirements.in
#
alabaster==0.7.13
# via sphinx
async-generator==1.10
# via -r doc-requirements.in
babel==2.12.1
# via sphinx
bcrypt==4.0.1
# via paramiko
cachetools==5.3.1
# via google-auth
certifi==2023.7.22
# via
# kubernetes
# requests
cffi==1.15.1
# via
# cryptography
# pynacl
charset-normalizer==3.2.0
# via requests
cryptography==41.0.3
# via paramiko
debtcollector==2.5.0
# via oslo-config
docutils==0.20.1
# via sphinx
google-auth==2.17.3
# via kubernetes
idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
jinja2==3.1.2
# via sphinx
juju==2.9.44.0
# via -r doc-requirements.in
jujubundlelib==0.5.7
# via theblues
kubernetes==27.2.0
# via juju
macaroonbakery==1.3.1
# via
# juju
# theblues
markupsafe==2.1.3
# via jinja2
mypy-extensions==1.0.0
# via typing-inspect
netaddr==0.8.0
# via oslo-config
oauthlib==3.2.2
# via
# kubernetes
# requests-oauthlib
oslo-config==9.1.1
# via -r doc-requirements.in
oslo-i18n==6.0.0
# via oslo-config
packaging==23.1
# via sphinx
paramiko==2.12.0
# via juju
pbr==5.11.1
# via
# oslo-i18n
# stevedore
protobuf==3.20.3
# via macaroonbakery
pyasn1==0.5.0
# via
# juju
# pyasn1-modules
# rsa
pyasn1-modules==0.3.0
# via google-auth
pycparser==2.21
# via cffi
pygments==2.16.1
# via sphinx
pymacaroons==0.13.0
# via macaroonbakery
pynacl==1.5.0
# via
# macaroonbakery
# paramiko
# pymacaroons
pyrfc3339==1.1
# via
# juju
# macaroonbakery
python-dateutil==2.8.2
# via kubernetes
pytz==2023.3
# via pyrfc3339
pyyaml==6.0.1
# via
# juju
# jujubundlelib
# kubernetes
# oslo-config
requests==2.31.0
# via
# kubernetes
# macaroonbakery
# oslo-config
# requests-oauthlib
# sphinx
# theblues
requests-oauthlib==1.3.1
# via kubernetes
rfc3986==2.0.0
# via oslo-config
rsa==4.9
# via google-auth
six==1.16.0
# via
# google-auth
# kubernetes
# macaroonbakery
# paramiko
# pymacaroons
# python-dateutil
snowballstemmer==2.2.0
# via sphinx
sphinx==7.1.2
# via
# -r doc-requirements.in
# sphinxcontrib-asyncio
sphinxcontrib-applehelp==1.0.4
# via sphinx
sphinxcontrib-asyncio==0.3.0
# via -r doc-requirements.in
sphinxcontrib-devhelp==1.0.2
# via sphinx
sphinxcontrib-htmlhelp==2.0.1
# via sphinx
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
stevedore==5.1.0
# via oslo-config
theblues==0.5.2
# via juju
toposort==1.10
# via juju
typing-extensions==4.7.1
# via typing-inspect
typing-inspect==0.9.0
# via juju
urllib3==2.0.6
# via
# kubernetes
# requests
websocket-client==1.6.1
# via kubernetes
websockets==11.0.3
# via juju
wrapt==1.15.0
# via debtcollector
2 changes: 0 additions & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ Utilities API documentation

controller-api
model-api
openstack-utils
tls-cert-utils
cli-utils
exception-utils
generic-utils
juju-utils
test-utils
5 changes: 0 additions & 5 deletions doc/source/openstack-utils.rst

This file was deleted.

5 changes: 0 additions & 5 deletions doc/source/test-utils.rst

This file was deleted.

3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ commands = /bin/true

[flake8]
ignore = E402,E226,W504
deps = -r{toxinidir}/test-requirements.txt
per-file-ignores =
unit_tests/**: D

[testenv:docs]
basepython = python3
changedir = doc/source
deps =
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/doc-requirements.txt
commands = sphinx-build -W -b html -d {toxinidir}/doc/build/doctrees . {toxinidir}/doc/build/html

[testenv:func]
Expand Down
16 changes: 8 additions & 8 deletions unit_tests/test_zaza_charm_lifecycle_func_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def test_func_test_runner(self):
lc_func_test_runner.func_test_runner(
force=True)
prepare_calls = [
mock.call('newmodel', test_directory=None),
mock.call('newmodel', test_directory=None)]
mock.call('newmodel', 'default_alias', test_directory=None),
mock.call('newmodel', 'default_alias', test_directory=None)]
cwd = os.getcwd()
deploy_calls = [
mock.call(cwd + '/tests/bundles/bundle1.yaml', 'newmodel',
Expand Down Expand Up @@ -157,10 +157,10 @@ def test_func_test_runner_cmr(self):
'zaza.charm_tests.ks.test.project_create2']}]}
lc_func_test_runner.func_test_runner()
prepare_calls = [
mock.call('m1', test_directory=None),
mock.call('m2', test_directory=None),
mock.call('m3', test_directory=None),
mock.call('m4', test_directory=None)]
mock.call('m1', 'default_alias', test_directory=None),
mock.call('m2', 'default_alias', test_directory=None),
mock.call('m3', 'model_alias_5', test_directory=None),
mock.call('m4', 'model_alias_6', test_directory=None)]
cwd = os.getcwd()
deploy_calls = [
mock.call(cwd + '/tests/bundles/bundle1.yaml', 'm1',
Expand Down Expand Up @@ -252,8 +252,8 @@ def test_func_test_runner_with_before_script(self):
lc_func_test_runner.func_test_runner()
cwd = os.getcwd()
prepare_calls = [
mock.call('newmodel', test_directory=None),
mock.call('newmodel', test_directory=None)]
mock.call('newmodel', 'default_alias', test_directory=None),
mock.call('newmodel', 'default_alias', test_directory=None)]
deploy_calls = [
mock.call(cwd + '/tests/bundles/bundle1.yaml', 'newmodel',
model_ctxt={'default_alias': 'newmodel'}, force=False,
Expand Down
29 changes: 29 additions & 0 deletions unit_tests/test_zaza_charm_lifecycle_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock

import zaza.charm_lifecycle.prepare as lc_prepare
import unit_tests.utils as ut_utils

Expand Down Expand Up @@ -53,3 +55,30 @@ def test_parser_logging(self):
# Using args
args = lc_prepare.parse_args(['-m', 'model', '--log', 'DEBUG'])
self.assertEqual(args.loglevel, 'DEBUG')

def test_main(self):
self.patch_object(lc_prepare.sys, "argv")
self.patch_object(lc_prepare, "cli_utils")
mock_args = mock.MagicMock()
self.patch_object(lc_prepare, "parse_args", return_value=mock_args)
self.patch_object(lc_prepare, "prepare")

# model
mock_args.model_name = "test_model"
mock_args.test_directory = None

lc_prepare.main()
self.prepare.assert_called_once_with("test_model", "default_alias",
test_directory=None)
mock_args.reset_mock()
self.prepare.reset_mock()

# alias:model
mock_args.model_name = "test_alias:test_model"
mock_args.test_directory = None

lc_prepare.main()
self.prepare.assert_called_once_with("test_model", "test_alias",
test_directory=None)
mock_args.reset_mock()
self.prepare.reset_mock()
32 changes: 31 additions & 1 deletion unit_tests/utilities/test_deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,38 @@ def test_get_overlay_ppas(self):
self.assertEqual(deployment_env.get_overlay_ppas(),
ro_types.ReadOnlyList(['ppa:ppa1', 'ppa:ppa2']))

config = collections.OrderedDict({'model_alias': {'overlay_ppas':
['ppa:ppa1', 'ppa:ppa2']}})
get_options_mock.return_value = ro_types.resolve_immutable(config)
self.assertEqual(deployment_env.get_overlay_ppas('model_alias'),
ro_types.ReadOnlyList(['ppa:ppa1', 'ppa:ppa2']))

config = collections.OrderedDict({'force_deploy': 'x-y'})
get_options_mock.return_value = ro_types.resolve_immutable(config)
self.assertEqual(deployment_env.get_overlay_ppas(), None)

def test_get_cloudinit_userdata(self):
with mock.patch.object(deployment_env, 'get_overlay_ppas',
return_value=None):
preferences_file = "/etc/apt/preferences.d/proposed-updates"
cloud_config = {
'apt': {
'sources': {}
},
'preruncmd': [
f"echo 'Package: *' >> {preferences_file}",
f"echo 'Pin: release a=*-proposed' >> {preferences_file}",
f"echo 'Pin-Priority: 500' >> {preferences_file}",
]
}
cloudinit_userdata = "#cloud-config\n{}".format(
yaml.safe_dump(cloud_config))
self.assertEqual(
deployment_env.get_cloudinit_userdata(),
cloudinit_userdata)
with mock.patch.object(deployment_env, 'get_overlay_ppas',
return_value=['ppa:ppa0', 'ppa:ppa1']):
preferences_file = "/etc/apt/preferences.d/proposed-updates"
cloud_config = {
'apt': {
'sources': {
Expand All @@ -79,7 +104,12 @@ def test_get_cloudinit_userdata(self):
'source': 'ppa:ppa1'
}
}
}
},
'preruncmd': [
f"echo 'Package: *' >> {preferences_file}",
f"echo 'Pin: release a=*-proposed' >> {preferences_file}",
f"echo 'Pin-Priority: 500' >> {preferences_file}",
]
}
cloudinit_userdata = "#cloud-config\n{}".format(
yaml.safe_dump(cloud_config))
Expand Down
1 change: 1 addition & 0 deletions zaza/charm_lifecycle/func_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def run_env_deployment(env_deployment, keep_model=DESTROY_MODEL, force=False,
for deployment in env_deployment.model_deploys:
prepare.prepare(
deployment.model_name,
deployment.model_alias,
test_directory=test_directory)

for deployment in env_deployment.model_deploys:
Expand Down
Loading

0 comments on commit 2b33642

Please sign in to comment.