Пример #1
0
class TestXenaChassisShell(unittest.TestCase):

    session = None

    def setUp(self):
        self.session = CloudShellAPISession('localhost', 'admin', 'admin',
                                            'Global')

    def tearDown(self):
        for resource in self.session.GetResourceList('Testing').Resources:
            self.session.DeleteResource(resource.Name)

    def testHelloWorld(self):
        pass

    def test_xena_chassis(self):
        self._get_inventory('xena-chassis', xena_chassis['xena-chassis'])

    def _get_inventory(self, name, properties):
        attributes = [
            AttributeNameValue('Xena Chassis Shell 2G.Password',
                               properties['password'])
        ]
        resource = create_autoload_resource(self.session,
                                            'Xena Chassis Shell 2G',
                                            properties['address'], name,
                                            attributes)
        self.session.AutoLoad(resource.Name)
        resource_details = self.session.GetResourceDetails(resource.Name)
        assert (len(resource_details.ChildResources) == properties['modules'])
        self.session.DeleteResource(resource.Name)
class TestIxiaChassis2GShell(unittest.TestCase):

    session = None

    def setUp(self):
        self.session = CloudShellAPISession('localhost', 'admin', 'admin',
                                            'Global')

    def tearDown(self):
        for resource in self.session.GetResourceList('Testing').Resources:
            self.session.DeleteResource(resource.Name)

    def testHelloWorld(self):
        pass

    def test_win_ixos(self):
        self._get_inventory('win-ixos', ixia_chassis['win-ixos'])

    def test_lin_ixos(self):
        self._get_inventory('lin-ixos', ixia_chassis['lin-ixos'])

    def test_all(self):
        for key, value in ixia_chassis.items():
            self._get_inventory(key, value)

    def _get_inventory(self, name, properties):
        self.resource = self.session.CreateResource(
            resourceFamily='CS_TrafficGeneratorChassis',
            resourceModel='Ixia Chassis Shell 2G',
            resourceName=name,
            resourceAddress=properties['address'],
            folderFullPath='Testing',
            parentResourceFullPath='',
            resourceDescription='should be removed after test')
        self.session.UpdateResourceDriver(self.resource.Name,
                                          'Ixia Chassis Shell 2G')
        attributes = [
            AttributeNameValue('Ixia Chassis Shell 2G.Controller Address',
                               properties['controller']),
            AttributeNameValue('Ixia Chassis Shell 2G.Controller TCP Port',
                               properties['port']),
            AttributeNameValue('Ixia Chassis Shell 2G.Client Install Path', '')
        ]
        self.session.SetAttributesValues(
            ResourceAttributesUpdateRequest(self.resource.Name, attributes))
        self.session.AutoLoad(self.resource.Name)
        resource_details = self.session.GetResourceDetails(self.resource.Name)
        assert (len(resource_details.ChildResources) == properties['modules'])
        self.session.DeleteResource(self.resource.Name)
Пример #3
0
def autoload_resource(session: CloudShellAPISession, test_helpers: TestHelpers,
                      server: str) -> ResourceInfo:
    """ Yields CPE resource for shell autoload testing. """
    resource = test_helpers.create_autoload_resource(BYTEBLOWER_CHASSIS_MODEL,
                                                     'test-byteblower', server)
    yield resource
    session.DeleteResource(resource.Name)
class TestIxiaChassis2GShell(object):

    session = None

    def setup(self):
        self.session = CloudShellAPISession('localhost', 'admin', 'admin',
                                            'Global')

    def teardown(self):
        for resource in self.session.GetResourceList('Testing').Resources:
            self.session.DeleteResource(resource.Name)

    def test_hello_world(self):
        pass

    def test_all(self):
        for key, value in ixchariot_servers.items():
            self._get_inventory(key, value)

    def _get_inventory(self, name, properties):
        self.resource = self.session.CreateResource(
            resourceFamily='CS_TrafficGeneratorChassis',
            resourceModel='IxChariot Server Shell 2G',
            resourceName=name,
            resourceAddress=properties['address'],
            folderFullPath='Testing',
            parentResourceFullPath='',
            resourceDescription='should be removed after test')
        self.session.UpdateResourceDriver(self.resource.Name,
                                          'IxChariot Server Shell 2G')
        attributes = [
            AttributeNameValue('IxChariot Server Shell 2G.Client Install Path',
                               properties['client_install_path']),
            AttributeNameValue('IxChariot Server Shell 2G.User',
                               properties['user']),
            AttributeNameValue('IxChariot Server Shell 2G.Password',
                               properties['password'])
        ]
        self.session.SetAttributesValues(
            ResourceAttributesUpdateRequest(self.resource.Name, attributes))
        self.session.AutoLoad(self.resource.Name)
        resource_details = self.session.GetResourceDetails(self.resource.Name)
        assert (len(resource_details.ChildResources) == properties['modules'])
        self.session.DeleteResource(self.resource.Name)
def autoload_resource(session: CloudShellAPISession, test_helpers: TestHelpers,
                      dut: list) -> ResourceInfo:
    address, controller_port, password, _ = dut
    attributes = [
        AttributeNameValue(f"{XENA_CHASSIS_MODEL}.Controller TCP Port",
                           controller_port),
        AttributeNameValue(f"{XENA_CHASSIS_MODEL}.Password", password),
    ]
    resource = test_helpers.create_autoload_resource(XENA_CHASSIS_MODEL,
                                                     "test-xena", address,
                                                     attributes)
    yield resource
    session.DeleteResource(resource.Name)
def autoload_resource(session: CloudShellAPISession, test_helpers: TestHelpers,
                      dut: list) -> ResourceInfo:
    address, controller_address, controller_port = dut
    attributes = [
        AttributeNameValue(f"{STC_CHASSIS_MODEL}.Controller Address",
                           controller_address),
        AttributeNameValue(f"{STC_CHASSIS_MODEL}.Controller TCP Port",
                           controller_port),
    ]
    resource = test_helpers.create_autoload_resource(STC_CHASSIS_MODEL,
                                                     "test-stc", address,
                                                     attributes)
    yield resource
    session.DeleteResource(resource.Name)
Пример #7
0
def autoload_resource(session: CloudShellAPISession, test_helpers: TestHelpers,
                      dut: List[str]) -> ResourceInfo:
    """Yields Ixia chassis resource for shell autoload testing."""
    address, controller_address, controller_port = dut
    attributes = [
        AttributeNameValue(f"{IXIA_CHASSIS_MODEL}.Controller Address",
                           controller_address),
        AttributeNameValue(f"{IXIA_CHASSIS_MODEL}.Controller TCP Port",
                           controller_port),
        AttributeNameValue(f"{IXIA_CHASSIS_MODEL}.User", "admin"),
        AttributeNameValue(f"{IXIA_CHASSIS_MODEL}.Password", "admin"),
    ]
    resource = test_helpers.create_autoload_resource(IXIA_CHASSIS_MODEL,
                                                     "test-folder/test-ixia",
                                                     address, attributes)
    yield resource
    session.DeleteResource(resource.Name)
from cloudshell.api.cloudshell_api import CloudShellAPISession, AttributeNameValue
from os import environ as parameter
import json

connectivity = json.loads(parameter["QUALICONNECTIVITYCONTEXT"])
reservationDetails = json.loads(parameter["RESERVATIONCONTEXT"])
resourceDetails = json.loads(parameter["RESOURCECONTEXT"])

domains_to_scan = parameter["domains"].split(',')
dry_run = parameter["dry_run"] != "False"


for domain in domains_to_scan:
    api = CloudShellAPISession(host=connectivity["serverAddress"], token_id=connectivity["adminAuthToken"], domain=domain)
    domain_details = api.GetDomainDetails(domain)
    resources_to_delete = [resource for resource in api.FindResources(attributeValues=[AttributeNameValue('Temp Resource', "Yes")], showAllDomains=domain == 'Global').Resources
                           if resource.FullPath is not None]
    for resource in resources_to_delete:
        if not dry_run:
            api.DeleteResource(resource.FullPath)
        print("Deleted resource {}".format(resource.FullPath))
    api.Logoff()