
This change includes: * New test class to test ovs/collector module. Added one test in the meantime to test get_env function. * loading configuration moved to a function, since it affects testing. * Added paramiko to test-requirements since it used by ovs/common * Minor improvement to get_env function. Change-Id: I606f1af74a7148057673df1e95c1c80e82777ec3
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
# 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.
|
|
import os
|
|
import tempfile
|
|
|
|
import openstack_dashboard.don.ovs.collector as collector
|
|
from openstack_dashboard.tests import base
|
|
|
|
|
|
class TestOvsCollector(base.TestCase):
|
|
"""Tests openvswitch collector module."""
|
|
def setUp(self):
|
|
super(TestOvsCollector, self).setUp()
|
|
|
|
# Create a temporary file
|
|
self.tmp_fd, self.tmp_fp = tempfile.mkstemp(dir=os.getcwd())
|
|
|
|
def tearDown(self):
|
|
super(TestOvsCollector, self).tearDown()
|
|
|
|
# Remove the file
|
|
os.remove(self.tmp_fp)
|
|
|
|
def test_get_env(self):
|
|
lines = ["export x=2", "export y=3", "z=4"]
|
|
with open(self.tmp_fp, 'w') as f:
|
|
f.write("\n".join(lines))
|
|
env = collector.get_env(os.path.basename(self.tmp_fp))
|
|
self.assertEqual(env, dict(x='2', y='3'))
|