Package starcluster :: Package tests :: Module test_config
[hide private]
[frames] | no frames]

Source Code for Module starcluster.tests.test_config

  1  import os 
  2  import tempfile 
  3   
  4  import logging 
  5  logging.disable(logging.WARN) 
  6   
  7  from starcluster.logger import log 
  8  from starcluster import exception 
  9  from starcluster.tests import StarClusterTest 
 10  from starcluster.static import STARCLUSTER_CFG_FILE 
 11  from starcluster.config import StarClusterConfig 
 12  from starcluster.tests.templates.config import default_config, config_test_template 
 13   
14 -class TestStarClusterConfig(StarClusterTest):
15
17 cfg = self.config
18
19 - def test_config_dne(self):
20 tmp_file = tempfile.NamedTemporaryFile() 21 non_existent_file = tmp_file.name 22 tmp_file.close() 23 assert not os.path.exists(non_existent_file) 24 try: 25 cfg = StarClusterConfig(non_existent_file, cache=True); cfg.load() 26 except exception.ConfigNotFound,e: 27 pass 28 else: 29 raise Exception('config loaded non-existent config file %s' % path)
30
31 - def test_get_cluster(self):
32 cluster = self.config.get_cluster_template('c1') 33 try: 34 self.config.get_cluster_template('no_such_cluster') 35 except exception.ClusterTemplateDoesNotExist,e: 36 pass 37 else: 38 raise Exception('config returned non-existent cluster')
39
40 - def test_int_required(self):
41 cases = [{'c1_size':'-s'}, {'c1_size': 2.5}, {'v1_partition': 'asdf'}, 42 {'v1_partition': 0.33}] 43 for case in cases: 44 try: 45 cfg = self.get_custom_config(**case) 46 except exception.ConfigError,e: 47 pass 48 else: 49 raise Exception('config is not enforcing ints correctly')
50
51 - def test_missing_required(self):
52 pass
53
54 - def test_volumes(self):
55 c1 = self.config.get_cluster_template('c1') 56 vols = c1.volumes 57 assert len(vols) == 3 58 assert vols.has_key('v1') 59 v1 = vols['v1'] 60 assert v1.has_key('volume_id') and v1['volume_id'] == 'vol-c999999' 61 assert v1.has_key('device') and v1['device'] == '/dev/sdj' 62 assert v1.has_key('partition') and v1['partition'] == '/dev/sdj1' 63 assert v1.has_key('mount_path') and v1['mount_path'] == '/volume1' 64 assert vols.has_key('v2') 65 v2 = vols['v2'] 66 assert v2.has_key('volume_id') and v2['volume_id'] == 'vol-c888888' 67 assert v2.has_key('device') and v2['device'] == '/dev/sdk' 68 assert v2.has_key('partition') and v2['partition'] == '/dev/sdk1' 69 assert v2.has_key('mount_path') and v2['mount_path'] == '/volume2' 70 assert vols.has_key('v3') 71 v3 = vols['v3'] 72 assert v3.has_key('volume_id') and v3['volume_id'] == 'vol-c777777' 73 assert v3.has_key('device') and v3['device'] == '/dev/sdl' 74 assert v3.has_key('partition') and v3['partition'] == '/dev/sdl1' 75 assert v3.has_key('mount_path') and v3['mount_path'] == '/volume3'
76
77 - def test_volume_not_defined(self):
78 try: 79 cfg = self.get_custom_config(**{'c1_vols': 'v1,v2,v2323'}) 80 except exception.ConfigError,e: 81 pass 82 else: 83 raise Exception('config allows non-existent volumes to be specified')
84
85 - def test_clusters(self):
86 assert self.config.clusters.has_key('c1') 87 assert self.config.clusters.has_key('c2') 88 assert self.config.clusters.has_key('c3')
89
90 - def test_extends(self):
91 c1 = self.config.clusters.get('c1') 92 c2 = self.config.clusters.get('c2') 93 c3 = self.config.clusters.get('c3') 94 c2_settings = ['__name__', 'extends', 'keyname', 'key_location', 'cluster_size', 'node_instance_type', 95 'master_instance_type', 'volumes'] 96 c3_settings = ['__name__', 'extends', 'keyname', 'key_location', 'cluster_size', 'volumes'] 97 for key in c1: 98 if c2.has_key(key) and not key in c2_settings: 99 assert c2[key] == c1[key] 100 else: 101 # below only true for default test config, not required in general 102 assert c2[key] != c1[key] 103 for key in c2: 104 if c3.has_key(key) and not key in c3_settings: 105 assert c3[key] == c2[key] 106 else: 107 # below only true for default test config, not required in general 108 assert c3[key] != c2[key]
109
110 - def test_plugins(self):
111 c1 = self.config.get_cluster_template('c1') 112 plugs = c1.plugins 113 assert len(plugs) == 3 114 # test that order is preserved 115 p1 = plugs[0] 116 p2 = plugs[1] 117 p3 = plugs[2] 118 assert p1['__name__'] == 'p1' 119 assert p1['setup_class'] == 'starcluster.tests.mytestplugin.SetupClass' 120 assert p1['my_arg'] == '23' 121 assert p1['my_other_arg'] == 'skidoo' 122 assert p2['__name__'] == 'p2' 123 assert p2['setup_class'] == 'starcluster.tests.mytestplugin.SetupClass2' 124 assert p2['my_arg'] == 'hello' 125 assert p2['my_other_arg'] == 'world' 126 assert p3['__name__'] == 'p3' 127 assert p3['setup_class'] == 'starcluster.tests.mytestplugin.SetupClass3' 128 assert p3['my_arg'] == 'bon' 129 assert p3['my_other_arg'] == 'jour' 130 assert p3['my_other_other_arg'] == 'monsignour'
131
132 - def test_plugin_not_defined(self):
133 try: 134 cfg = self.get_custom_config(**{'c1_plugs': 'p1,p2,p233'}) 135 except exception.ConfigError,e: 136 pass 137 else: 138 raise Exception('config allows non-existent plugins to be specified')
139
140 - def test_keypairs(self):
141 kpairs = self.config.keys 142 assert len(kpairs) == 3 143 k1 = kpairs.get('k1') 144 k2 = kpairs.get('k2') 145 k3 = kpairs.get('k3') 146 assert k1 and k1['key_location'] == '/path/to/k1_rsa' 147 assert k2 and k2['key_location'] == '/path/to/k2_rsa' 148 assert k3 and k3['key_location'] == '/path/to/k3_rsa'
149
150 - def test_keypair_not_defined(self):
151 try: 152 cfg = self.get_custom_config(**{'c1_keyname': 'k2323'}) 153 except exception.ConfigError,e: 154 pass 155 else: 156 raise Exception('config allows non-existent keypairs to be specified')
157
158 - def test_invalid_config(self):
159 """ 160 Test that reading a non-INI formatted file raises an exception 161 """ 162 tmp_file = tempfile.NamedTemporaryFile() 163 tmp_file.write("""<html>random garbage file with no section headings</html>""") 164 tmp_file.flush() 165 try: 166 cfg = StarClusterConfig(tmp_file.name, cache=True); cfg.load() 167 except exception.ConfigHasNoSections,e: 168 pass 169 else: 170 raise Exception("config allows non-INI formatted files")
171
172 - def test_empty_config(self):
173 """ 174 Test that reading an empty config generates no errors and that aws 175 credentials can be read from the environment. 176 """ 177 aws_key = 'testkey' 178 aws_secret_key = 'testsecret' 179 os.environ['AWS_ACCESS_KEY_ID'] = aws_key 180 os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_key 181 tmp_file = tempfile.NamedTemporaryFile() 182 cfg = StarClusterConfig(tmp_file.name, cache=True); cfg.load() 183 assert cfg.aws['aws_access_key_id'] == aws_key 184 assert cfg.aws['aws_secret_access_key'] == aws_secret_key
185