예제 #1
0
    def test_vpn_dict_state_running(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {
            'id': 1,
            'created_at': isonow,
            'fixed_ip': {
                'address': '127.0.0.1'
            }
        }

        project = type('Project', (object, ), {
            'id': 'project',
            'vpn_ip': '127.0.0.1',
            'vpn_port': 1234
        })

        # Returns state running for 127.0.0.1 - look at class setup
        expected_vpn_dict = {
            'project_id': 'project',
            'public_ip': '127.0.0.1',
            'public_port': 1234,
            'internal_ip': '127.0.0.1',
            'instance_id': ec2utils.id_to_ec2_id(1),
            'created_at': utils.isotime(isonow),
            'state': 'running'
        }

        self.assertEqual(expected_vpn_dict,
                         admin.vpn_dict(project, vpn_instance))
예제 #2
0
    def test_vpn_dict_non_vpn_instance(self):
        project = type('Project', (object,), {'id': 'project',
                                              'vpn_ip': '127.0.0.1',
                                              'vpn_port': '1234'})

        expected_vpn_dict = {'project_id': 'project',
                             'public_ip': '127.0.0.1',
                             'public_port': '1234',
                             'state': 'pending'}

        self.assertEqual(expected_vpn_dict, admin.vpn_dict(project, None))
예제 #3
0
    def test_vpn_dict_state_down(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {'id': 1,
                        'created_at': isonow,
                        'fixed_ip': {'address': '127.0.0.1'}}

        project = type('Project', (object,), {'id': 'project',
                                              'vpn_ip': '127.0.0.2',
                                              'vpn_port': 1234})

        # Returns state down for 127.0.0.2 - look at class setup
        vpn_dict = admin.vpn_dict(project, vpn_instance)
        self.assertEqual('down', vpn_dict['state'])
예제 #4
0
    def test_vpn_dict_non_vpn_instance(self):
        project = type('Project', (object, ), {
            'id': 'project',
            'vpn_ip': '127.0.0.1',
            'vpn_port': '1234'
        })

        expected_vpn_dict = {
            'project_id': 'project',
            'public_ip': '127.0.0.1',
            'public_port': '1234',
            'state': 'pending'
        }

        self.assertEqual(expected_vpn_dict, admin.vpn_dict(project, None))
예제 #5
0
    def test_vpn_dict_invalid_project_vpn_config(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {'id': 1,
                        'created_at': isonow,
                        'fixed_ip': {'address': '127.0.0.1'}}

        # Inline project object - vpn_port of None to make it invalid
        project = type('Project', (object,), {'id': 'project',
                                              'vpn_ip': '127.0.0.2',
                                              'vpn_port': None})

        # Returns state down for 127.0.0.2 - look at class setup
        vpn_dict = admin.vpn_dict(project, vpn_instance)
        self.assertEqual('down - invalid project vpn config',
                         vpn_dict['state'])
예제 #6
0
    def test_vpn_dict_state_down(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {
            'id': 1,
            'created_at': isonow,
            'fixed_ip': {
                'address': '127.0.0.1'
            }
        }

        project = type('Project', (object, ), {
            'id': 'project',
            'vpn_ip': '127.0.0.2',
            'vpn_port': 1234
        })

        # Returns state down for 127.0.0.2 - look at class setup
        vpn_dict = admin.vpn_dict(project, vpn_instance)
        self.assertEqual('down', vpn_dict['state'])
예제 #7
0
    def test_vpn_dict_invalid_project_vpn_config(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {
            'id': 1,
            'created_at': isonow,
            'fixed_ip': {
                'address': '127.0.0.1'
            }
        }

        # Inline project object - vpn_port of None to make it invalid
        project = type('Project', (object, ), {
            'id': 'project',
            'vpn_ip': '127.0.0.2',
            'vpn_port': None
        })

        # Returns state down for 127.0.0.2 - look at class setup
        vpn_dict = admin.vpn_dict(project, vpn_instance)
        self.assertEqual('down - invalid project vpn config',
                         vpn_dict['state'])
예제 #8
0
    def test_vpn_dict_state_running(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {'id': 1,
                        'created_at': isonow,
                        'fixed_ip': {'address': '127.0.0.1'}}

        project = type('Project', (object,), {'id': 'project',
                                              'vpn_ip': '127.0.0.1',
                                              'vpn_port': 1234})

        # Returns state running for 127.0.0.1 - look at class setup
        expected_vpn_dict = {'project_id': 'project',
                             'public_ip': '127.0.0.1',
                             'public_port': 1234,
                             'internal_ip': '127.0.0.1',
                             'instance_id':
                                ec2utils.id_to_ec2_id(1),
                             'created_at': utils.isotime(isonow),
                             'state': 'running'}

        self.assertEqual(expected_vpn_dict,
                         admin.vpn_dict(project, vpn_instance))