Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)