-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I6650a0a58b4e6c8932f5e20ae7d29d948c765112
- Loading branch information
Showing
15 changed files
with
192 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,3 +115,6 @@ docs/source/rst | |
|
||
# IntelliJ project folder | ||
.idea/ | ||
|
||
# General | ||
local-cluster/_hco/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ before_script: | |
|
||
test: | ||
script: | ||
- tox | ||
- tox -e code-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Local cluster preparations | ||
CLUSTER_DIR := local-cluster/_hco | ||
export KUBEVIRT_PROVIDER ?= k8s-1.18 | ||
export KUBEVIRT_NUM_NODES ?= 2 | ||
export KUBEVIRT_NUM_SECONDARY_NICS ?= 4 | ||
export KUBEVIRT_WITH_CNAO=true | ||
|
||
# Helper scripts | ||
HACK_DIR := local-cluster/hack | ||
CLUSTER_UP := $(HACK_DIR)/cluster-up.sh | ||
CLUSTER_DOWN := $(HACK_DIR)/cluster-down.sh | ||
|
||
# If not specified otherwise, local cluster's KUBECONFIG will be used | ||
export KUBECONFIG ?= $(CLUSTER_DIR)/_kubevirtci/_ci-configs/$(KUBEVIRT_PROVIDER)/.kubeconfig | ||
|
||
all: check | ||
|
||
cluster-up: $(CLUSTER_UP) | ||
$(CLUSTER_UP) | ||
|
||
cluster-down: $(CLUSTER_DOWN) | ||
$(CLUSTER_DOWN) | ||
|
||
check: cluster-down cluster-up | ||
tox | ||
|
||
.PHONY: \ | ||
cluster-down \ | ||
cluster-up \ | ||
check |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash -e | ||
|
||
script_dir=$(dirname "$(readlink -f "$0")") | ||
hco_dir=local-cluster/_hco | ||
|
||
pushd $hco_dir | ||
make cluster-down | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
script_dir=$(dirname "$(readlink -f "$0")") | ||
hco_dir=local-cluster/_hco | ||
|
||
rm -rf $hco_dir | ||
git clone https://github.com/kubevirt/hyperconverged-cluster-operator.git $hco_dir | ||
pushd $hco_dir | ||
make cluster-up | ||
make cluster-sync | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: kubevirt.io/v1alpha3 | ||
kind: VirtualMachine | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
kubevirt.io/vm: {{ name }} | ||
name: {{ name }} | ||
spec: | ||
running: false | ||
template: | ||
metadata: | ||
creationTimestamp: null | ||
spec: | ||
domain: | ||
cpu: | ||
cores: 1 | ||
devices: | ||
disks: | ||
- disk: | ||
bus: virtio | ||
name: containerdisk | ||
interfaces: | ||
- masquerade: {} | ||
name: default | ||
machine: | ||
type: "" | ||
resources: | ||
requests: | ||
memory: 1024Mi | ||
networks: | ||
- name: default | ||
pod: {} | ||
terminationGracePeriodSeconds: 30 | ||
volumes: | ||
- containerDisk: | ||
image: quay.io/openshift-cnv/qe-cnv-tests-fedora:33 | ||
name: containerdisk | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import kubernetes | ||
import pytest | ||
from openshift.dynamic import DynamicClient | ||
from resources.namespace import Namespace | ||
from resources.pod import Pod | ||
from resources.virtual_machine import VirtualMachine | ||
from tests.utils import generate_yaml_from_template | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def client(): | ||
return DynamicClient(client=kubernetes.config.new_client_from_config()) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def namespace(): | ||
with Namespace(name="namespace-for-tests") as ns: | ||
yield ns | ||
|
||
|
||
def test_get(client): | ||
Pod.get(dyn_client=client) | ||
|
||
|
||
def test_create(): | ||
with Namespace(name="test-namespace"): | ||
pass | ||
|
||
|
||
def test_vm(namespace): | ||
name = "test-vm" | ||
with VirtualMachine( | ||
name=name, namespace=namespace.name, body=generate_yaml_from_template(name=name) | ||
): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
|
||
import jinja2 | ||
import yaml | ||
|
||
|
||
class MissingTemplateVariables(Exception): | ||
def __init__(self, var, template): | ||
self.var = var | ||
self.template = template | ||
|
||
def __str__(self): | ||
return f"Missing variables {self.var} for template {self.template}" | ||
|
||
|
||
def generate_yaml_from_template(**kwargs): | ||
""" | ||
Generate JSON from yaml file_ | ||
Keyword Args: | ||
name (str): | ||
image (str): | ||
Returns: | ||
dict: Generated from template file | ||
Raises: | ||
MissingTemplateVariables: If not all template variables exists | ||
Examples: | ||
generate_yaml_from_template(file_='path/to/file/name', name='vm-name-1') | ||
""" | ||
file_ = "tests/manifests/vm.yaml" | ||
with open(file_, "r") as stream: | ||
data = stream.read() | ||
|
||
# Find all template variables | ||
template_vars = [i.split()[1] for i in re.findall(r"{{ .* }}", data)] | ||
for var in template_vars: | ||
if var not in kwargs.keys(): | ||
raise MissingTemplateVariables(var=var, template=file_) | ||
|
||
template = jinja2.Template(source=data) | ||
out = template.render(**kwargs) | ||
return yaml.safe_load(stream=out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
[tox] | ||
envlist=code-check | ||
skipsdist=True | ||
envlist = code-check,tests | ||
skipsdist = True | ||
|
||
[flake8] | ||
[testenv:code-check] | ||
basepython = python3 | ||
setenv = PYTHONPATH = {toxinidir} | ||
deps= | ||
deps = | ||
pre-commit | ||
commands = | ||
pre-commit run --all-files | ||
|
||
[testenv:tests] | ||
basepython = python3 | ||
setenv = | ||
PYTHONPATH = {toxinidir} | ||
passenv = | ||
KUBECONFIG | ||
deps = | ||
pytest | ||
commands = | ||
pip install . | ||
pytest tests |