Add basis for action plugin tests

This commit is contained in:
Will Miller 2018-09-14 13:35:27 +00:00
parent 78dfa05258
commit 794bffd701
6 changed files with 88 additions and 3 deletions

View File

View File

@ -86,7 +86,7 @@ class ActionModule(ActionBase):
old_idxs = {} old_idxs = {}
new_idxs = {} new_idxs = {}
next_idx = 0 next_idx = 0
used_idxs = old_idxs.values() used_idxs = list(old_idxs.values())
for name, dev in six.iteritems(specified_mappings): for name, dev in six.iteritems(specified_mappings):
try: try:
# We need to re-use the IDXs of any existing physnets. # We need to re-use the IDXs of any existing physnets.
@ -97,7 +97,6 @@ class ActionModule(ActionBase):
next_idx += 1 next_idx += 1
used_idxs.append(next_idx) used_idxs.append(next_idx)
idx = next_idx idx = next_idx
finally:
new_idxs[name] = idx new_idxs[name] = idx
state[hostname]['physnet_indices'] = new_idxs state[hostname]['physnet_indices'] = new_idxs

View File

@ -4,3 +4,6 @@
ansible-lint>=3.0.0 # MIT ansible-lint>=3.0.0 # MIT
flake8>=3.5.0 # MIT flake8>=3.5.0 # MIT
# Required for Python 2
mock>=2.0.0 # BSD
stestr>=1.0.0 # Apache-2.0

0
tests/__init__.py Normal file
View File

View File

@ -0,0 +1,81 @@
# Copyright (c) 2018 StackHPC Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import imp
import os
import sys
import unittest
# Python 2/3 compatibility.
try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock
# Import method lifted from kolla_ansible's test_merge_config.py
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))
PLUGIN_FILE = os.path.join(PROJECT_DIR,
'ansible/action_plugins/tenks_update_state.py')
tus = imp.load_source('tenks_update_state', PLUGIN_FILE)
class TestTenksUpdateState(unittest.TestCase):
def setUp(self):
# Pass dummy arguments to allow instantiation of action plugin.
self.mod = tus.ActionModule(None, None, None, None, None, None)
# Minimal inputs required.
self.node_types = {
'type0': {
'memory_mb': 1024,
'vcpus': 2,
'volumes': [
{
'capacity': '10GB',
},
],
'physical_networks': [
'physnet0',
],
},
}
self.specs = [
{
'type': 'type0',
'count': 2,
'ironic_config': {
'resource_class': 'testrc',
},
},
]
self.hypervisor_vars = {
'foo': {
'physnet_mappings': {
'physnet0': 'dev0',
},
'ipmi_port_range_start': 100,
'ipmi_port_range_end': 102,
},
}
def test__set_physnet_idxs_no_state(self):
state = {}
self.mod._set_physnet_idxs(state, self.hypervisor_vars)
expected_indices = {
'physnet0': 0,
}
self.assertEqual(state['foo']['physnet_indices'], expected_indices)

View File

@ -21,6 +21,8 @@ deps =
-c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/rocky} -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/rocky}
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
commands =
stestr run {posargs}
[testenv:pep8] [testenv:pep8]
basepython = python2.7 basepython = python2.7