Skip to content

Commit

Permalink
tests: make unit and func tests pass again
Browse files Browse the repository at this point in the history
This changes are mostly working on the test codes to make sure they are
passing for the upcoming jammy support. In addition to that, it removes some
old workarounds that are not needed anymore.

There's still one open issue about the functional tests. See below.

Since this is a big change, here is a summary of changes.

Makefile:
  - remove workaround for the closed issue[0] where symlinks breaking
    charm push
  - introduce standard rename.sh

tests/unit:
  - mock a bunch of stuff that were trying to modify system files/dirs

tests/functional:
  - remove workaround for the closed issue[1] where zaza was not
    respecting local_overlay_enabled key
  - fix the issue where zaza waits for ubuntu charms indefinitely due to
    empty message[2]
  - add missing required config key in iscsi test
  - charmstore -> charmhub

src:
  - get rid of commented code in production
  - add missing quotes to a config.yaml default key

---

Currently open issues:
tests/functional:
  - focal-fc bundle is not running, probably needs special hardware
    judging by the constraint given in the bundle file. However it is not
    listed in gate or smoke bundles, so it is not blocking the release.

[0] canonical/charmcraft#109
[1] openstack-charmers/zaza#379
[2] openstack-charmers/zaza#436

Signed-off-by: Mert Kırpıcı <[email protected]>
  • Loading branch information
Mert Kırpıcı committed Aug 17, 2022
1 parent 083848b commit 17b428f
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 99 deletions.
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PYTHON := /usr/bin/python3

PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST)))
ifndef CHARM_BUILD_DIR
CHARM_BUILD_DIR=${PROJECTPATH}.build
CHARM_BUILD_DIR=${PROJECTPATH}
endif
METADATA_FILE="metadata.yaml"
CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}')
Expand All @@ -16,28 +16,23 @@ help:
@echo " make release - run clean and build targets"
@echo " make lint - run flake8 and black"
@echo " make proof - run charm proof"
@echo " make unit - run the tests defined in the unittest subdirectory"
@echo " make func - run the tests defined in the functional subdirectory"
@echo " make unittests - run the tests defined in the unittest subdirectory"
@echo " make functional - run the tests defined in the functional subdirectory"
@echo " make test - run lint, proof, unittests and functional targets"
@echo ""

clean:
@echo "Cleaning files"
@git clean -fXd
@echo "Cleaning existing build"
@rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}
@rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}.charm

build:
@charmcraft build
@charmcraft pack --verbose
@bash -c ./rename.sh

# bypassing bug https://github.com/canonical/charmcraft/issues/109
unpack: build
@mkdir -p ${CHARM_BUILD_DIR}/${CHARM_NAME}
@echo "Unpacking built .charm into ${CHARM_BUILD_DIR}/${CHARM_NAME}"
@cd ${CHARM_BUILD_DIR}/${CHARM_NAME} && unzip -q ${CHARM_BUILD_DIR}/${CHARM_NAME}.charm

release: clean build unpack
@echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}"
release: clean build
@echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}.charm"

lint:
@echo "Running lint checks"
Expand Down
19 changes: 19 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type: charm
parts:
charm:
charm-python-packages: [setuptools]
bases:
- build-on:
- name: ubuntu
channel: "20.04"
architectures: ["amd64"]
run-on:
- name: ubuntu
channel: "20.04"
architectures:
- amd64
- name: ubuntu
channel: "18.04"
architectures:
- amd64

2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ options:
"hostname2": "iqn.yyyy-mm.naming-authority:uniquename2}'
multipath-defaults:
type: string
default: "{user_friendly_names: yes}"
default: '{"user_friendly_names": "yes"}'
description: |
In multipath config, sets the defaults configuration. String should be of JSON dictionary format.
Double quotes are essential to the correct format of this JSON string.
Expand Down
3 changes: 0 additions & 3 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ tags:
- fibrechannel
- fiberchannel
subordinate: true
series:
- bionic
- focal
requires:
host:
interface: juju-info
Expand Down
13 changes: 13 additions & 0 deletions rename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
charm=$(grep -E "^name:" metadata.yaml | awk '{print $2}')
echo "renaming ${charm}_*.charm to ${charm}.charm"
echo -n "pwd: "
pwd
ls -al
echo "Removing previous charm if it exists"
if [[ -e "${charm}.charm" ]];
then
rm "${charm}.charm"
fi
echo "Renaming charm here."
mv ${charm}_*.charm ${charm}.charm
13 changes: 1 addition & 12 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ class StorageConnectorCharm(CharmBase):
ISCSI_SERVICES = ['iscsid', 'open-iscsi']
MULTIPATHD_SERVICE = 'multipathd'

# ISCSI_MANDATORY_CONFIG = [
# 'storage-type',
# 'iscsi-target',
# 'iscsi-port',
# 'multipath-devices'
# ]
# FC_MANDATORY_CONFIG = [
# 'storage-type',
# 'fc-lun-alias',
# 'multipath-devices'
# ]
VALID_STORAGE_TYPES = ["fc", "iscsi"]
MANDATORY_CONFIG = {
"iscsi": [
Expand Down Expand Up @@ -320,7 +309,7 @@ def _multipath_configuration(self, tenv):
config = charm_config.get('multipath-' + section)
if config:
logging.info("Gather information for the multipaths section " + section)
logging.debug("multipath-" + section + " data: " + config)
logging.debug("multipath-" + section + " data: " + str(config))
try:
ctxt[section] = json.loads(config)
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions tests/functional/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
git+https://github.com/openstack-charmers/zaza.git#egg=zaza
git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack
20 changes: 18 additions & 2 deletions tests/functional/storage-connector-func-tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def configure_iscsi_connector(self):
'iscsi-node-session-auth-password': 'password123',
'iscsi-node-session-auth-username-in': 'iscsi-target',
'iscsi-node-session-auth-password-in': 'secretpass',
'multipath-devices': '{}'
}
zaza.model.set_application_config('iscsi-connector', conf)
zaza.model.set_application_config('storage-connector', conf)

def get_unit_full_hostname(self, unit_name):
"""Retrieve the full hostname of a unit."""
Expand All @@ -59,7 +60,22 @@ def test_iscsi_connector(self):
"""Test iscsi configuration and wait for idle status."""
self.configure_iscsi_connector()
logging.info('Wait for idle/ready status...')
zaza.model.wait_for_application_states()
zaza.model.wait_for_application_states(
states={
"storage-connector": {
"workload-status": "active",
"workload-status-message-prefix": "Unit is ready"
},
"ubuntu": {
"workload-status": "active",
"workload-status-message-regex": "^$"
},
"ubuntu-target": {
"workload-status": "active",
"workload-status-message-regex": "^$"
}
}
)

def test_validate_iscsi_session(self):
"""Validate that the iscsi session is active."""
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/tests/bundles/bionic.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
local_overlay_enabled: True
series: bionic
applications:
ubuntu-target:
charm: cs:ubuntu
charm: ch:ubuntu
num_units: 1
storage-connector:
charm: #path is defined in overlay because of bug https://github.com/openstack-charmers/zaza/issues/379
ubuntu:
charm: cs:ubuntu
charm: ch:ubuntu
num_units: 1
relations:
- - 'ubuntu:juju-info'
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/tests/bundles/focal-fc.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
local_overlay_enabled: True
series: focal
applications:
storage-connector:
charm: #path is defined in overlay because of bug https://github.com/openstack-charmers/zaza/issues/379
options:
storage-type: 'fc'
fc-lun-alias: 'data1'
multipath-defaults: '{"user_friendly_names":"yes", "find_multipaths":"yes", "polling_interval":"10"}'
multipath-devices: '{"vendor":"PURE", "product":"FlashArray", "fast_io_fail_tmo":"10", "path_selector":"queue-length 0", "path_grouping_policy":"group_by_prio", "rr_min_io":"1", "path_checker":"tur", "fast_io_fail_tmo":"1", "dev_loss_tmo":"infinity", "no_path_retry":"5", "failback":"immediate", "prio":"alua", "hardware_handler":"1 alua", "max_sectors_kb":"4096"}'
ubuntu:
charm: cs:ubuntu
charm: ch:ubuntu
num_units: 1
to:
- 0
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/tests/bundles/focal.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
local_overlay_enabled: True
series: focal
applications:
ubuntu-target:
charm: cs:ubuntu
charm: ch:ubuntu
num_units: 1
storage-connector:
charm: #path is defined in overlay because of bug https://github.com/openstack-charmers/zaza/issues/379
ubuntu:
charm: cs:ubuntu
charm: ch:ubuntu
num_units: 1
relations:
- - 'ubuntu:juju-info'
Expand Down
4 changes: 0 additions & 4 deletions tests/functional/tests/bundles/overlays/bionic.yaml.j2

This file was deleted.

4 changes: 0 additions & 4 deletions tests/functional/tests/bundles/overlays/focal-fc.yaml.j2

This file was deleted.

4 changes: 0 additions & 4 deletions tests/functional/tests/bundles/overlays/focal.yaml.j2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
applications:
{{ charm_name }}:
charm: "{{ CHARM_BUILD_DIR }}/{{ charm_name }}.charm"
8 changes: 7 additions & 1 deletion tests/functional/tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ tests:
target_deploy_status:
storage-connector:
workload-status: blocked
workload-status-message: "Missing"
workload-status-message-prefix: "Missing"
ubuntu:
workload-status: active
workload-status-message-regex: "^$"
ubuntu-target:
workload-status: active
workload-status-message-regex: "^$"
4 changes: 3 additions & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"""Init mocking for unit tests."""

import sys
from unittest import mock

import mock
from ops import testing

testing.SIMULATE_CAN_CONNECT = True

sys.path.append('src')

Expand Down
Loading

0 comments on commit 17b428f

Please sign in to comment.