summaryrefslogtreecommitdiffstats
path: root/testcases/tests/TestFunctestUtils.py
blob: 46da50cb80a495ec8056990abc0857312fabc1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import unittest
import os
import sys
import yaml

sys.path.append("../")
from functest_utils import getTestEnv, isTestRunnable, generateTestcaseList


class TestFunctestUtils(unittest.TestCase):

    def setUp(self):
        os.environ["INSTALLER_TYPE"] = "fuel"
        os.environ["SDN_CONTROLLER"] = "odl"
        os.environ["OPNFV_FEATURE"] = "ovs2.4"

        global functest_yaml

        with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
            functest_yaml = yaml.safe_load(f)
            f.close()

    def test_getTestEnv(self):

        env_test = getTestEnv('ovno', functest_yaml)
        self.assertEqual(env_test, {'controller': 'opencontrail'})

        env_test = getTestEnv('doctor', functest_yaml)
        self.assertEqual(env_test, None)

        env_test = getTestEnv('promise', functest_yaml)
        self.assertEqual(env_test, None)

        env_test = getTestEnv('functest/tempest', functest_yaml)
        self.assertEqual(env_test, None)

        env_test = getTestEnv('functest/vims', functest_yaml)
        self.assertEqual(env_test, None)

        env_test = getTestEnv('functest/odl', functest_yaml)
        self.assertEqual(env_test, {'controller': 'odl'})

        env_test = getTestEnv('functest/onos', functest_yaml)
        self.assertEqual(env_test, {'controller': 'onos'})

        env_test = getTestEnv('functest/onos-ovsdb', functest_yaml)
        self.assertEqual(env_test, {'controller': 'onos'})

        env_test = getTestEnv('policy-test', functest_yaml)
        self.assertEqual(env_test, {'controller': 'odl'})

        env_test = getTestEnv('sdnvpn/odl-vpn_service-tests', functest_yaml)
        self.assertEqual(env_test,
                         {'controller': 'odl', 'scenario': 'os_ovh_ha'})

        env_test = getTestEnv('sdnvpn/opnfv-yardstick-tc026-sdnvpn',
                              functest_yaml)
        self.assertEqual(env_test,
                         {'controller': 'nosdn', 'scenario': 'os_ovh_ha'})

        env_test = getTestEnv('sdnvpn/openstack-neutron-bgpvpn-api-extension-tests',
                              functest_yaml)
        self.assertEqual(env_test,
                         {'controller': 'nosdn', 'scenario': 'os_ovh_ha'})

        env_test = getTestEnv('foo', functest_yaml)
        self.assertEqual(env_test, '')

    def test_isTestRunnable(self):

        test = isTestRunnable('ovno', functest_yaml)
        self.assertFalse(test)

        test = isTestRunnable('doctor', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('promise', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('functest/onos', functest_yaml)
        self.assertFalse(test)

        test = isTestRunnable('functest/odl', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('functest/vping', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('functest/tempest', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('functest/rally', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('functest/vims', functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('sdnvpn/odl-vpn_service-tests',
                              functest_yaml)
        self.assertTrue(test)

        test = isTestRunnable('sdnvpn/opnfv-yardstick-tc026-sdnvpn',
                              functest_yaml)
        self.assertFalse(test)

    def test_generateTestcaseList(self):

        test = generateTestcaseList(functest_yaml)
        test = sorted(test.split(' '))
        expected_list = "doctor vims odl rally vping tempest promise policy-test odl-vpn_service-tests "
        expected_list_array = sorted(expected_list.split(' '))
        
        self.assertEqual(test, expected_list_array)

    def tearDown(self):
        os.environ["INSTALLER_TYPE"] = ""
        os.environ["SDN_CONTROLLER"] = ""
        os.environ["OPNFV_FEATURE"] = ""


if __name__ == '__main__':
    unittest.main()