monasca-agent/tests/test_config.py
Tim Kuhlman 19cd1c053e Remove emit_time from the collector and put it into the forwarder.
Fixed the service dimension for api checks on various openstack services
so that it matches that of the other service checks, allowing for it to
be grouped together.

Modified the config so a config in the working dir can be used this is
helpful for testing. Additionally I fixed up few tests and removed
some no longer used, there is a lot of work with test left unfinished

Change-Id: Ic5b127db41c174735f1436bb511f00e271274cb0
2015-02-04 14:54:00 -07:00

65 lines
1.9 KiB
Python

# -*- coding: latin-1 -*-
import unittest
import os.path
import tempfile
from monasca_agent.common.config import Config
from monasca_agent.common.util import PidFile, is_valid_hostname
class TestConfig(unittest.TestCase):
def testWhiteSpaceConfig(self):
"""Leading whitespace confuse ConfigParser
"""
agent_config = Config.get_config(
cfg_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "badconfig.conf"))
self.assertEqual(agent_config["api_key"], "1234")
def testGoodPidFie(self):
"""Verify that the pid file succeeds and fails appropriately"""
pid_dir = tempfile.mkdtemp()
program = 'test'
expected_path = os.path.join(pid_dir, '%s.pid' % program)
pid = "666"
pid_f = open(expected_path, 'w')
pid_f.write(pid)
pid_f.close()
p = PidFile(program, pid_dir)
self.assertEqual(p.get_pid(), 666)
# clean up
self.assertEqual(p.clean(), True)
self.assertEqual(os.path.exists(expected_path), False)
def testHostname(self):
valid_hostnames = [
u'i-123445',
u'5dfsdfsdrrfsv',
u'432498234234A'
u'234234235235235235', # Couldn't find anything in the RFC saying it's not valid
u'A45fsdff045-dsflk4dfsdc.ret43tjssfd',
u'4354sfsdkfj4TEfdlv56gdgdfRET.dsf-dg',
u'r' * 255,
]
not_valid_hostnames = [
u'abc' * 150,
u'sdf4..sfsd',
u'$42sdf',
u'.sfdsfds'
u's™£™£¢ª•ªdfésdfs'
]
for hostname in valid_hostnames:
self.assertTrue(is_valid_hostname(hostname), hostname)
for hostname in not_valid_hostnames:
self.assertFalse(is_valid_hostname(hostname), hostname)
if __name__ == '__main__':
unittest.main()