def test_vpn_ping_bad_id(self, mock_socket): """Server sends an unknown packet ID.""" self.setup_socket(mock_socket, self.fake_reply_packet(pkt_id=0x41)) rc = utils.vpn_ping(self.address, self.port, session_id=self.session_id) self.assertFalse(rc)
def test_vpn_ping_timeout(self, mock_socket): """Server doesn't reply within timeout.""" self.setup_socket(mock_socket, None, socket.timeout) rc = utils.vpn_ping(self.address, self.port, session_id=self.session_id) self.assertFalse(rc)
def test_vpn_ping_bad_len(self, mock_socket): """Test a short/invalid server reply.""" self.setup_socket(mock_socket, 'fake_reply') rc = utils.vpn_ping(self.address, self.port, session_id=self.session_id) self.assertFalse(rc)
def _vpn_dict(self, context, project_id, instance): elevated = context.elevated() rv = {'project_id': project_id} if not instance: rv['state'] = 'pending' return rv rv['instance_id'] = instance['uuid'] rv['created_at'] = utils.isotime(instance['created_at']) nw_info = common.get_nw_info_for_instance(elevated, instance) if not nw_info: return rv vif = nw_info[0] ips = [ip for ip in vif.fixed_ips() if ip['version'] == 4] if ips: rv['internal_ip'] = ips[0]['address'] network = self.network_api.get(elevated, vif['network']['id']) if network: vpn_ip = network['vpn_public_address'] vpn_port = network['vpn_public_port'] rv['public_ip'] = vpn_ip rv['public_port'] = vpn_port if vpn_ip and vpn_port: if utils.vpn_ping(vpn_ip, vpn_port): rv['state'] = 'running' else: rv['state'] = 'down' else: rv['state'] = 'invalid' return rv
def vpn_dict(project, vpn_instance): rv = {'project_id': project.id, 'public_ip': project.vpn_ip, 'public_port': project.vpn_port} if vpn_instance: rv['instance_id'] = vpn_instance['ec2_id'] rv['created_at'] = utils.isotime(vpn_instance['created_at']) address = vpn_instance.get('fixed_ip', None) if address: rv['internal_ip'] = address['address'] if utils.vpn_ping(project.vpn_ip, project.vpn_port): rv['state'] = 'running' else: rv['state'] = 'down' else: rv['state'] = 'pending' return rv
def vpn_dict(project, vpn_instance): rv = {"project_id": project.id, "public_ip": project.vpn_ip, "public_port": project.vpn_port} if vpn_instance: rv["instance_id"] = ec2utils.id_to_ec2_id(vpn_instance["id"]) rv["created_at"] = utils.isotime(vpn_instance["created_at"]) address = vpn_instance.get("fixed_ip", None) if address: rv["internal_ip"] = address["address"] if project.vpn_ip and project.vpn_port: if utils.vpn_ping(project.vpn_ip, project.vpn_port): rv["state"] = "running" else: rv["state"] = "down" else: rv["state"] = "down - invalid project vpn config" else: rv["state"] = "pending" return rv
def _vpn_dict(self, project, vpn_instance): rv = {'project_id': project.id, 'public_ip': project.vpn_ip, 'public_port': project.vpn_port} if vpn_instance: rv['instance_id'] = vpn_instance['uuid'] rv['created_at'] = utils.isotime(vpn_instance['created_at']) address = vpn_instance.get('fixed_ip', None) if address: rv['internal_ip'] = address['address'] if project.vpn_ip and project.vpn_port: if utils.vpn_ping(project.vpn_ip, project.vpn_port): rv['state'] = 'running' else: rv['state'] = 'down' else: rv['state'] = 'invalid' else: rv['state'] = 'pending' return rv
def _vpn_dict(self, context, project_id, instance): elevated = context.elevated() rv = {"project_id": project_id} if not instance: rv["state"] = "pending" return rv rv["instance_id"] = instance["uuid"] rv["created_at"] = timeutils.isotime(instance["created_at"]) nw_info = compute_utils.get_nw_info_for_instance(instance) if not nw_info: return rv vif = nw_info[0] ips = [ip for ip in vif.fixed_ips() if ip["version"] == 4] if ips: rv["internal_ip"] = ips[0]["address"] # NOTE(vish): Currently network_api.get does an owner check on # project_id. This is probably no longer necessary # but rather than risk changes in the db layer, # we are working around it here by changing the # project_id in the context. This can be removed # if we remove the project_id check in the db. elevated.project_id = project_id network = self.network_api.get(elevated, vif["network"]["id"]) if network: vpn_ip = network["vpn_public_address"] vpn_port = network["vpn_public_port"] rv["public_ip"] = vpn_ip rv["public_port"] = vpn_port if vpn_ip and vpn_port: if utils.vpn_ping(vpn_ip, vpn_port): rv["state"] = "running" else: rv["state"] = "down" else: rv["state"] = "invalid" return rv
def _vpn_dict(self, context, project_id, instance): elevated = context.elevated() rv = {'project_id': project_id} if not instance: rv['state'] = 'pending' return rv rv['instance_id'] = instance['uuid'] rv['created_at'] = timeutils.isotime(instance['created_at']) nw_info = compute_utils.get_nw_info_for_instance(instance) if not nw_info: return rv vif = nw_info[0] ips = [ip for ip in vif.fixed_ips() if ip['version'] == 4] if ips: rv['internal_ip'] = ips[0]['address'] # NOTE(vish): Currently network_api.get does an owner check on # project_id. This is probably no longer necessary # but rather than risk changes in the db layer, # we are working around it here by changing the # project_id in the context. This can be removed # if we remove the project_id check in the db. elevated.project_id = project_id network = self.network_api.get(elevated, vif['network']['id']) if network: vpn_ip = network['vpn_public_address'] vpn_port = network['vpn_public_port'] rv['public_ip'] = vpn_ip rv['public_port'] = vpn_port if vpn_ip and vpn_port: if utils.vpn_ping(vpn_ip, vpn_port): rv['state'] = 'running' else: rv['state'] = 'down' else: rv['state'] = 'invalid' return rv
def test_vpn_ping_ok(self, mock_socket): self.setup_socket(mock_socket, self.fake_reply_packet()) rc = utils.vpn_ping(self.address, self.port, session_id=self.session_id) self.assertTrue(rc)