コード例 #1
0
    def test_parse_multi_host_config(self):
        """Test parse_host_config with multiple host-port values """
        hosts = '192.168.1.10:1234,192.168.1.11:1235,192.168.1.12:1236'
        ret = utils.parse_host_config(hosts, OVERRIDE_PORT)
        self.assertTrue(isinstance(ret, tuple))
        self.assertThat(
            ret,
            matchers.Equals((('192.168.1.10', 1234), ('192.168.1.11', 1235),
                             ('192.168.1.12', 1236))))

        hosts = '192.168.1.10:1234,192.168.1.11,192.168.1.12:1236'
        ret = utils.parse_host_config(hosts, OVERRIDE_PORT)
        self.assertTrue(isinstance(ret, tuple))
        self.assertThat(
            ret,
            matchers.Equals(
                (('192.168.1.10', 1234), ('192.168.1.11', OVERRIDE_PORT),
                 ('192.168.1.12', 1236))))
コード例 #2
0
    def test_parse_single_host_config(self):
        """Test parse_host_config with an IP or Host value """
        ret = utils.parse_host_config('192.168.1.10', OVERRIDE_PORT)
        self.assertThat(ret,
                        matchers.Equals((('192.168.1.10', OVERRIDE_PORT), )))

        ret = utils.parse_host_config('host1.lab1.mc', OVERRIDE_PORT)
        self.assertThat(
            ret, matchers.Equals(((
                'host1.lab1.mc',
                OVERRIDE_PORT,
            ), )))

        ret = utils.parse_host_config('192.168.1.10:123', OVERRIDE_PORT)
        self.assertThat(ret, matchers.Equals(((
            '192.168.1.10',
            123,
        ), )))

        ret = utils.parse_host_config('host1.lab1.mc:123', OVERRIDE_PORT)
        self.assertThat(ret, matchers.Equals(((
            'host1.lab1.mc',
            123,
        ), )))
コード例 #3
0
ファイル: mech_vpp.py プロジェクト: tiewei/networking-vpp
    def __init__(self):
        super(EtcdAgentCommunicator, self).__init__()
        LOG.debug("Using etcd host:%s port:%s user:%s password:***" %
                  (cfg.CONF.ml2_vpp.etcd_host,
                   cfg.CONF.ml2_vpp.etcd_port,
                   cfg.CONF.ml2_vpp.etcd_user,))

        host = nwvpp_utils.parse_host_config(cfg.CONF.ml2_vpp.etcd_host,
                                             cfg.CONF.ml2_vpp.etcd_port)
        self.etcd_client = etcd.Client(host=host,
                                       username=cfg.CONF.ml2_vpp.etcd_user,
                                       password=cfg.CONF.ml2_vpp.etcd_pass,
                                       allow_reconnect=True)
        # We need certain directories to exist
        self.state_key_space = LEADIN + '/state'
        self.port_key_space = LEADIN + '/nodes'
        self.secgroup_key_space = LEADIN + '/global/secgroups'
        self.election_key_space = LEADIN + '/election'
        self.do_etcd_mkdir(self.state_key_space)
        self.do_etcd_mkdir(self.port_key_space)
        self.do_etcd_mkdir(self.secgroup_key_space)
        self.do_etcd_mkdir(self.election_key_space)
        self.secgroup_enabled = cfg.CONF.SECURITYGROUP.enable_security_group
        if self.secgroup_enabled:
            self.register_secgroup_event_handler()

        # TODO(ijw): .../state/<host> lists all known hosts, and they
        # heartbeat when they're functioning

        self.db_q_ev = eventlet.event.Event()
        try:
            # Liberty, Mitaka
            ev = events.AFTER_INIT
        except Exception:
            # Newton and on
            ev = events.AFTER_CREATE

        # Clear any previously elected master keys from the election key space
        EtcdHelper(self.etcd_client).clear_state(self.election_key_space)
        registry.subscribe(self.start_threads, resources.PROCESS, ev)
コード例 #4
0
 def test_parse_fishy_host_config(self):
     """Test parse_host_config with non-string value """
     with ExpectedException(vpp_agent_exec.InvalidEtcHostsConfig):
         utils.parse_host_config(1, OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostsConfig):
         utils.parse_host_config(None, OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config(',', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1,', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config(',host2', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1,,host2', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1::123', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:123:123', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:123:', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:,host2', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1::123,host2', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:123:123,host2', OVERRIDE_PORT)
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('host1:123:,host2', OVERRIDE_PORT)
コード例 #5
0
 def test_parse_empty_host_config(self):
     """Test parse_host_config with empty value """
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config('', OVERRIDE_PORT)
コード例 #6
0
 def test_parse_single_host_new_format(self):
     """Test parse_host_config with single host new format """
     hosts = '192.168.1.10:1234'
     ret = utils.parse_host_config(hosts, OVERRIDE_PORT)
     self.assertTrue(isinstance(ret, tuple))
     self.assertThat(ret, matchers.Equals((('192.168.1.10', 1234), )))
コード例 #7
0
 def test_parse_multi_host_invalid_config(self):
     """Test parse_host_config with invalid host-port value """
     hosts = '192.168.1.10:fred,192.168.1.11,192.168.1.12:1236'
     with ExpectedException(vpp_agent_exec.InvalidEtcHostConfig):
         utils.parse_host_config(hosts, OVERRIDE_PORT)