Change-Id: Ie2fea14d2cbfb2c0b78cdc3064df0a558fa28a4cchanges/34/696534/9
parent
baa509f5a9
commit
f90a6d42b3
@ -0,0 +1,3 @@
|
||||
[DEFAULT]
|
||||
test_path=${TEST_PATH:-./tripleo_ansible/tests/}
|
||||
top_dir=./
|
@ -0,0 +1 @@
|
||||
ansible>=2.8
|
@ -1,2 +1,5 @@
|
||||
pre-commit # MIT
|
||||
netaddr # BSD
|
||||
mock>=2.0.0 # BSD
|
||||
stestr>=2.0.0 # Apache-2.0
|
||||
oslotest>=3.2.0 # Apache-2.0
|
||||
|
@ -0,0 +1,21 @@
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 oslotest import base
|
||||
|
||||
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
"""Test case base class for all unit tests."""
|
@ -0,0 +1,258 @@
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 tripleo_ansible.ansible_plugins.filter import helpers
|
||||
from tripleo_ansible.tests import base as tests_base
|
||||
|
||||
|
||||
class TestHelperFilters(tests_base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHelperFilters, self).setUp()
|
||||
self.filters = helpers.FilterModule()
|
||||
|
||||
def test_subsort(self):
|
||||
dict = {
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone'
|
||||
},
|
||||
'haproxy': {
|
||||
'image': 'quay.io/tripleo/haproxy'
|
||||
},
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
expected_ordered_dict = {
|
||||
0: [
|
||||
{'haproxy': {
|
||||
'image': 'quay.io/tripleo/haproxy',
|
||||
'start_order': 0
|
||||
}},
|
||||
{'mysql': {
|
||||
'image': 'quay.io/tripleo/mysql',
|
||||
'start_order': 0
|
||||
}}
|
||||
],
|
||||
1: [
|
||||
{'keystone': {
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'start_order': 1
|
||||
}}
|
||||
]
|
||||
}
|
||||
result = self.filters.subsort(dict_to_sort=dict,
|
||||
attribute='start_order')
|
||||
self.assertEqual(result, expected_ordered_dict)
|
||||
|
||||
def test_subsort_with_null_value(self):
|
||||
dict = {
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone'
|
||||
},
|
||||
'haproxy': {
|
||||
'image': 'quay.io/tripleo/haproxy'
|
||||
},
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
expected_ordered_dict = {
|
||||
0: [
|
||||
{'mysql': {
|
||||
'image': 'quay.io/tripleo/mysql',
|
||||
'start_order': 0
|
||||
}}
|
||||
],
|
||||
1: [
|
||||
{'keystone': {
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'start_order': 1
|
||||
}}
|
||||
],
|
||||
5: [
|
||||
{'haproxy': {
|
||||
'image': 'quay.io/tripleo/haproxy',
|
||||
'start_order': 5
|
||||
}}
|
||||
]
|
||||
}
|
||||
result = self.filters.subsort(dict_to_sort=dict,
|
||||
attribute='start_order', null_value=5)
|
||||
self.assertEqual(result, expected_ordered_dict)
|
||||
|
||||
def test_singledict(self):
|
||||
list = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_dict = {
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone'
|
||||
},
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
result = self.filters.singledict(list)
|
||||
self.assertEqual(result, expected_dict)
|
||||
|
||||
def test_list_of_keys(self):
|
||||
keys = [
|
||||
{
|
||||
'foo1': 'bar1'
|
||||
},
|
||||
{
|
||||
'foo2': 'bar2'
|
||||
},
|
||||
]
|
||||
expected_list = ['foo1', 'foo2']
|
||||
result = self.filters.list_of_keys(keys)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(batched_container_data=data,
|
||||
attribute='restart', value='always')
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_reverse(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(batched_container_data=data,
|
||||
attribute='restart',
|
||||
value='always',
|
||||
reverse=True)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_any(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(batched_container_data=data,
|
||||
attribute='restart',
|
||||
any=True)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_any_reverse(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(batched_container_data=data,
|
||||
attribute='restart',
|
||||
reverse=True,
|
||||
any=True)
|
||||
self.assertEqual(result, expected_list)
|
Loading…
Reference in new issue