Exemple #1
0
    def test_load_no_port(self):
        hosts = [
            dict(host='2.2.2.8', auth={
                'username': '******',
                'pass': '******'
            })
        ]
        pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
        self.assertRaisesRegexp(exceptions.ConfigurationError,
                                "Port not provided for host: 2.2.2.8",
                                lambda: list(pool.load()))

        hosts = [dict(ip_range='2.2.2.8/29')]
        pool = yaml_pool.YAMLPoolLoader({
            'hosts': hosts,
            'default': {
                'auth': {
                    'username': '******',
                    'password': '******'
                }
            }
        })
        self.assertRaisesRegexp(exceptions.ConfigurationError,
                                'Port not provided for host: 2.2.2.9',
                                lambda: list(pool.load()))
Exemple #2
0
 def test_good_keyfile(self):
     fd, good_file = tempfile.mkstemp()
     os.close(fd)
     config = {
         'default': {
             'auth': {
                 'username': '******'
             },
             'port': 123
         },
         'hosts': [{
             'host': 'google.com',
             'auth': {
                 'username': '******',
                 'keyfile': good_file
             },
             'port': 80
         }]
     }
     try:
         config_loader = yaml_pool.YAMLPoolLoader(config)
         self.assertEquals(
             config_loader.load().next(),
             dict(host='google.com',
                  auth=dict(username='******', keyfile=good_file),
                  port=80,
                  public_address=None))
     finally:
         os.unlink(good_file)
Exemple #3
0
 def test_bad_keyfile(self):
     tmp_dir = tempfile.mkdtemp()
     config = {
         'default': {
             'auth': {
                 'username': '******'
             },
             'port': 123
         },
         'hosts': [{
             'host': 'google.com',
             'auth': {
                 'username': '******',
                 'keyfile': tmp_dir + '/wrong_file'
             },
             'port': 80
         }]
     }
     try:
         pool = yaml_pool.YAMLPoolLoader(config)
         self.assertRaisesRegexp(
             exceptions.ConfigurationError,
             'does not exist or does not have the '
             'proper permissions',
             pool.load().next)
     finally:
         os.rmdir(tmp_dir)
Exemple #4
0
 def test_load_no_auth(self):
     hosts = [dict(host='2.2.2.8', port=22)]
     pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
     self.assertRaisesRegexp(
         exceptions.ConfigurationError,
         'Authentication not provided for host: 2.2.2.8',
         lambda: list(pool.load()))
Exemple #5
0
    def _load_pool(self, pool):
        config_loader = yaml_pool.YAMLPoolLoader(pool)
        hosts = config_loader.load()
        for host in hosts:

            # initial values for the hosts.
            # these will update over time.
            host.update({'alive': False, 'reserved': False, 'host_id': None})
            self.storage.add_host(host)
Exemple #6
0
 def test_load_ip_range(self):
     hosts = [
         dict(ip_range='2.2.2.8/29',
              auth={
                  'username': '******',
                  'pass': '******'
              },
              port=22)
     ]
     pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
     saved_hosts = list(pool.load())
     self.assertEqual(len(saved_hosts), 6)
Exemple #7
0
 def test_load_no_host_no_ip_range(self):
     hosts = [{
         'auth': {
             'username': '******',
             'pass': '******'
         },
         'port': 22
     }]
     pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
     self.assertRaisesRegexp(
         exceptions.ConfigurationError,
         "A host must define either the 'host' or the 'ip_range' key",
         lambda: list(pool.load()))
Exemple #8
0
 def _load_pool(self, pool):
     utils.write_to_log('backend._load_pool', "Starting...")
     config_loader = yaml_pool.YAMLPoolLoader(pool)
     utils.write_to_log('backend._load_pool', "after config_loader")
     hosts = config_loader.load()
     utils.write_to_log('backend._load_pool', "after config_loader.load()")
     for host in hosts:
         utils.write_to_log('backend._load_pool', "host ...")
         # initial values for the hosts.
         # these will update over time.
         host.update({'alive': False, 'reserved': False, 'host_id': None})
         utils.write_to_log('backend._load_pool', "b4 add_host ...")
         self.storage.add_host(host)
         utils.write_to_log('backend._load_pool', "after add_host")
Exemple #9
0
 def test_load_unsupported_host_key(self):
     hosts = [
         dict(ip='2.2.2.8',
              auth={
                  'username': '******',
                  'pass': '******'
              },
              port=22)
     ]
     pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
     self.assertRaisesRegexp(
         exceptions.ConfigurationError,
         "A host must define either the 'host' or the 'ip_range' key",
         lambda: list(pool.load()))
Exemple #10
0
    def test_merge_auth_dictionary(self):

        hosts = [dict(host='2.2.2.8', auth={'password': '******'}, port=22)]

        pool = yaml_pool.YAMLPoolLoader({
            'hosts': hosts,
            'default': {
                'auth': {
                    'username': '******'
                }
            }
        })
        host = pool.load().next()
        self.assertEqual(host['auth']['username'], 'adam')
        self.assertEqual(host['auth']['password'], 'pass2')
Exemple #11
0
    def test_load_host(self):
        hosts = [
            dict(host='2.2.2.1',
                 port=22,
                 auth={
                     'username': '******',
                     'pass': '******'
                 }),
            dict(host='2.2.2.2',
                 port=22,
                 auth={
                     'username': '******',
                     'pass': '******'
                 })
        ]

        pool = yaml_pool.YAMLPoolLoader({'hosts': hosts})
        saved_hosts = list(pool.load())
        self.assertEqual(len(saved_hosts), len(hosts))
Exemple #12
0
 def test_load_config(self):
     _file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                          'resources/pool.yaml')
     pool = yaml_pool.YAMLPoolLoader(_file)
     loaded_hosts = list(pool.load())
     self.assertEqual(len(loaded_hosts), 4)