Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_0020_update_rate_limit(self):
"""Updates existing rate limit of gateway.
It will trigger the cli command configure-rate-limits list
"""
self._config = Environment.get_config()
config = self._config['external_network']
ext_name = config['name']
result = self._runner.invoke(
gateway,
args=[
'configure-rate-limits', 'list', self._name
])
self.assertEqual(0, result.exit_code)
vm_resource = vapp.get_vm(VmTest._test_vapp_vmtools_vm_name)
VmTest._test_vapp_vmtools_vm_href = vm_resource.get('href')
self.assertIsNotNone(VmTest._test_vapp_vmtools_vm_href)
temp_name = config['vcd']['default_template_file_name']
VmTest._test_vapp_href = create_customized_vapp_from_template(
client=VmTest._client,
vdc=vdc1,
name=VmTest._vapp_name,
catalog_name=catalog_name,
template_name=temp_name)
self.assertIsNotNone(VmTest._test_vapp_href)
VmTest._sys_admin_client = Environment.get_sys_admin_client()
resource = VmTest._sys_admin_client.get_extension()
result = VmTest._sys_admin_client.get_linked_resource(
resource, RelationType.DOWN,
EntityType.DATASTORE_REFERENCES.value)
if hasattr(result, '{' + NSMAP['vcloud'] + '}Reference'):
for reference in result['{' + NSMAP['vcloud'] + '}Reference']:
datastore_id = reference.get('id')
VmTest._datastore_id = datastore_id.split(':')[3]
break
self.assertIsNotNone(VmTest._datastore_id)
def test_04_create_role(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
role_name = self.config['vcd']['role_name']
org.create_role(role_name, 'test description', ('Disk: View Properties',))
role_record = org.get_role_record(role_name)
assert self.config['vcd']['role_name'] == role_record.get('name')
def test_09_add_rights_to_Role(self):
org_in_use = self.config['vcd']['org_in_use']
org = Org(self.client, href=self.client.get_org_by_name(org_in_use).get('href'))
role_name = self.config['vcd']['role_name']
right_name = self.config['vcd']['right_name']
role_record = org.get_role_record(role_name)
role = Role(self.client, href=role_record.get('href'))
updated_role_resource = role.add_rights([right_name], org)
success = False
if hasattr(updated_role_resource, 'RightReferences') and \
hasattr(updated_role_resource.RightReferences, 'RightReference'):
for right in updated_role_resource.RightReferences.RightReference:
if right.get('name') == right_name:
success = True
break
assert success
def test_07_link_role_to_template(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
role_name = self.config['vcd']['role_name']
role_record = org.get_role_record(role_name)
role = Role(self.client, href=role_record.get('href'))
role.link()
def test_050_change_idisk_owner(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, resource=vdc_resource)
user_resource = org.get_user(
self.config['vcd']['idisk_new_owner_name'])
vdc.change_disk_owner(name=self.config['vcd']['idisk_name'],
user_href=user_resource.get('href'))
disk_resource = vdc.get_disk(self.config['vcd']['idisk_name'])
new_user = disk_resource.Owner.User.get('name')
assert self.config['vcd']['idisk_new_owner_name'] == new_user
def test_020_get_all_disks(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, resource=vdc_resource)
disks = vdc.get_disks()
assert len(disks) > 0
assert disks[0].get('name') == self.config['vcd']['idisk_name']
def test_010_get_storage_profiles(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, resource=vdc_resource)
profiles = vdc.get_storage_profiles()
assert len(profiles) > 0
def test_0060_vdc_metadata(self):
"""Test the methods related to metadata manipulation in vdc.py.
This test passes if all the metadata operations are successful.
"""
vapp_author_client = None
sys_admin_client = None
try:
logger = Environment.get_default_logger()
vapp_author_client = Environment.get_client_in_default_org(
CommonRoles.VAPP_AUTHOR)
vdc_vapp_author_view = VDC(client=vapp_author_client,
href=get_non_admin_href(
TestOrgVDC._new_vdc_href))
sys_admin_client = Environment.get_sys_admin_client()
vdc_sys_admin_view = VDC(client=sys_admin_client,
href=TestOrgVDC._new_vdc_href)
# try to add new metadata as vapp author
try:
logger.debug(f'Adding metadata [key={TestOrgVDC._metadata_key}'
', value={TestOrgVDC._metadata_value}]) as vApp '
'author')
vdc_vapp_author_view.set_metadata(
key=TestOrgVDC._metadata_key,
value=TestOrgVDC._metadata_value)
self.assertFail('vApp author shouldn\'t have been able to '
'add new metadta entry.')
except OperationNotSupportedException as e:
pass
# add new metadata as sys admin
logger.debug(f'Adding metadata [key={TestOrgVDC._metadata_key},'
'value={TestOrgVDC._metadata_value}]) as Sys admin.')
def test_10_remove_last_vdc_access(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, resource=vdc_resource)
vdc.share_with_org_members()
control_access = vdc.remove_access_settings(
access_settings_list=[
{'name': self.config['vcd']['access_user1'], 'type': 'user'}
])
self.assertFalse(hasattr(control_access, 'AccessSettings'))