Пример #1
0
    def test_auth_login_password(self, mock_config, mock_token):
        fake_login = "******"
        fake_pwd = "fake_pwd"
        fake_domain = "fake_domain"
        fake_token = 'fake_token'

        mock_config.return_value.config_file = {
            'domain': [fake_domain],
            'vcac_servers': {
                'PRD': 'fake_srv'
            },
            'tenant': {
                'PRD': ''
            }
        }
        mock_token.return_value = fake_token

        authenticate = VraAuthenticate('PRD')
        authenticate.auth_login_password(fake_login, fake_pwd, fake_domain)

        self.assertEqual(authenticate.login, fake_login)
        self.assertEqual(authenticate.domain, fake_domain)
        self.assertEqual(authenticate.token, fake_token)
        mock_token.assert_called_once()
        mock_token.assert_called_with(fake_login, fake_pwd)
Пример #2
0
    def test_get_token(self, mock_config):
        mock_config.return_value.verify = False
        mock_config.return_value.timeout = 12
        fake_login = "******"
        fake_pwd = "fake_pwd"
        fake_domain = "fake_domain"

        mock_config.return_value.session.post.return_value.status_code = 200
        mock_config.return_value.config_file = {
            'domain': [fake_domain],
            'vcac_servers': {
                'PRD': 'fake_srv'
            },
            'tenant': {
                'PRD': ''
            }
        }
        mock_config.return_value.session.post.return_value.text = '{"id":"fake_token"}'
        authenticate = VraAuthenticate('PRD')

        authenticate.get_token(fake_login, fake_pwd)

        mock_config.return_value.session.post.assert_called_once_with(
            'https://fake_srv/identity/api/tokens',
            headers={
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
            json={
                'username': '******',
                'password': '******',
                'tenant': ''
            },
            timeout=12,
            verify=False)
Пример #3
0
    def test_validate_payload_v6(self, mock_session):
        mock_session.return_value.get.side_effect = get_side_effect
        mock_session.return_value.post.side_effect = post_side_effect

        VraConfig(get_test_config_file_path())
        auth = VraAuthenticate('PRD').auth_login_password(
            'fake_login', 'fake_password', 'foo.fuu.com')
        sdk = VraSdk(auth, 'fake_bg')

        data = {
            "payload_version": 6,
            "provider-fake_data1": "fake_value1",
            "fake_data2": 122
        }

        fake_item_request = sdk.request_catalog_item("fake_catalog_item",
                                                     **data)
        self.assertTrue(
            self.validator.catalog_item(fake_item_request.payload.customized))

        fake_action_request = sdk.request_resource_action(
            "fake_action_name", "fake_resource_id", **data)
        self.assertTrue(
            self.validator.resource_action(
                fake_action_request.payload.customized))
Пример #4
0
    def test_auth_login_token_(self, mock_config):
        fake_login = "******"
        fake_domain = "fake_domain"
        fake_token = 'fake_token'

        mock_config.return_value.config_file = {
            'domain': [fake_domain],
            'vcac_servers': {
                'PRD': 'fake_srv'
            },
            'tenant': {
                'PRD': ''
            }
        }

        authenticate = VraAuthenticate('PRD')
        authenticate.auth_login_token(fake_login, fake_token, fake_domain)

        self.assertEqual(authenticate.login, fake_login)
        self.assertEqual(authenticate.domain, fake_domain)
        self.assertEqual(authenticate.token, fake_token)
Пример #5
0
    def test_get_token_raises_request(self, mock_config):
        mock_config.return_value.session.post.side_effect = RequestException()
        mock_config.return_value.config_file = {
            'domain': ['fake_domain'],
            'vcac_servers': {
                'PRD': ''
            },
            'tenant': {
                'PRD': ''
            }
        }

        with self.assertRaises(VraSdkRequestException):
            VraAuthenticate('PRD').get_token("", "")

        mock_config.assert_called_once()
Пример #6
0
    def test_vra_authenticate_init(self, mock_config, mock_urllib3):
        env = "PRD"
        serv = "fake_server"

        mock_config.return_value.config = {
            'vcac_servers': {
                env: serv
            },
            'tenant': {
                env: ''
            }
        }
        authenticate = VraAuthenticate('PRD')

        mock_config.assert_called_once()
        mock_urllib3.assert_called_once()
        self.assertEqual(authenticate.environment, 'PRD')
        self.assertIsNone(authenticate.login)
        self.assertIsNone(authenticate.requestedFor)
        self.assertIsNone(authenticate.token)
        self.assertIsNone(authenticate.domain)
Пример #7
0
from vra_sdk.vra_config import VraConfig
from vra_sdk.vra_authenticate import VraAuthenticate
from vra_sdk.vra_sdk import VraSdk
import os
from pprint import pprint as pprint

# credential loading from environment var
domain = "foo.fuu.com"
environment = os.environ['vra_environment']
login = os.environ['vra_login']
password = os.environ['vra_password']
######

# authentication part
VraConfig('config.json')
auth = VraAuthenticate(environment).auth_login_password(
    login, password, domain)
my_business_group = 'my_bg_name'
my_client = VraSdk(auth, my_business_group)
######

# get data on one vm from name
vm_name = 'my_vm_name'
vm_data = my_client.get_data('vm', 'name', vm_name)[0]
print(vm_data.id)
######

# get data on one vm from id
vm_id = 'my_vm_id'
vm_data = my_client.get_data('vm', 'id', vm_id)
print(vm_data.name)