Esempio n. 1
0
    def test_create_vm_pool(self, proxy, cloud_account, vm_pool_name):
        '''Configure vm pool

        Arguments:
            proxy              - a pytest fixture proxy to RwMcYang
            cloud_account_name - a pytest fixture for the cloud account name
            vm_pool_name       - a pytest fixture for the VM pool name

        Asserts:
            A cloud account exists for the cloud_account_name
            Newly configured vm pool has no resources assigned to it

        '''
        xpath = "/cloud-account/account[name='%s']" % cloud_account.name
        cloud_account = proxy.get(xpath)
        assert cloud_account is not None

        pool_config = RwMcYang.VmPool(
                name=vm_pool_name,
                cloud_account=cloud_account.name,
                dynamic_scaling=True,
        )
        proxy.create_config('/vm-pool/pool', pool_config)
        pool = proxy.get("/vm-pool/pool[name='%s']" % vm_pool_name)
        assigned_ids = [vm.id for vm in pool.assigned]
        assert len(assigned_ids) == 0
Esempio n. 2
0
    def test_create_vm_pool_with_bogus_cloud_name(self, proxy,
                                                  secondary_vm_pool_name):
        '''Tests that a vm pool cannot be created if the cloud name is None

        Arguments:
            proxy          - a pytest fixture proxy to RwMcYang
            secondary_vm_pool_name - a pytest fixture for the secondary vm pool name

        Asserts:
            Secondary vm pool name exists
            Secondary vm pool does not exist
            Cloud account does not exist for the bogus cloud account name
            rift.auto.proxy.ProxyRequestError is raised

        '''
        assert secondary_vm_pool_name is not None
        assert proxy.get(
            "/vm-pool/pool[name='%s']" % secondary_vm_pool_name) is None

        bogus_cloud_account_name = 'bogus-cloud-account-name'
        cloud_account = proxy.get("/cloud-account/account[name='%s']" %
                                  bogus_cloud_account_name)
        assert cloud_account is None

        pool_config = RwMcYang.VmPool(
            name=secondary_vm_pool_name,
            cloud_account=bogus_cloud_account_name,
            dynamic_scaling=True,
        )
        with pytest.raises(ProxyRequestError):
            proxy.create_config('/vm-pool/pool', pool_config)
Esempio n. 3
0
    def test_create_vm_pool_with_blank_cloud_name(self, proxy,
                                                  secondary_vm_pool_name):
        '''Tests that a vm pool cannot be created with a name that already exists

        Arguments:
            proxy                  - a pytest fixture proxy to RwMcYang
            secondary_vm_pool_name - a pytest fixture for the secondary vm pool name

        Asserts:
            Secondary vm pool name exists
            Secondary vm pool does not exist
            rift.auto.proxy.ProxyRequestError is raised

        '''
        assert secondary_vm_pool_name is not None
        assert proxy.get(
            "/vm-pool/pool[name='%s']" % secondary_vm_pool_name) is None

        pool_config = RwMcYang.VmPool(
            name=secondary_vm_pool_name,
            cloud_account='',
            dynamic_scaling=True,
        )
        with pytest.raises(ProxyRequestError):
            proxy.create_config('/vm-pool/pool', pool_config)
Esempio n. 4
0
    def test_create_vm_pool_with_duplicate_name(self, proxy, vm_pool_name,
                                                cloud_account):
        '''Tests that a vm pool cannot be created with a name that already exists

        Arguments:
            proxy         - a pytest fixture proxy to RwMcYang
            vm_pool_name  - a pytest fixture for the vm pool name
            cloud_account - a pytest fixture for the cloud account

        Asserts:
            Cloud account has a name
            rift.auto.proxy.ProxyRequestError is raised

        '''
        xpath = "/cloud-account/account[name='%s']" % cloud_account.name
        cloud_account = proxy.get(xpath)
        assert cloud_account.name is not None

        pool_config = RwMcYang.VmPool(
            name=vm_pool_name,
            cloud_account=cloud_account.name,
            dynamic_scaling=True,
        )
        with pytest.raises(ProxyRequestError):
            proxy.create_config('/vm-pool/pool', pool_config)
Esempio n. 5
0
    def test_create_vm_pool(self, proxy, cloud_account_name, vm_pool_name):
        '''Configure vm pool

        Asserts :
            Newly configured vm pool has no resources assigned to it
        '''
        pool_config = RwMcYang.VmPool(name=vm_pool_name,
                                      cloud_account=cloud_account_name)
        proxy.create_config('/vm-pool/pool', pool_config)

        pool = proxy.get("/vm-pool/pool[name='%s']" % vm_pool_name)
        assigned_ids = [vm.id for vm in pool.assigned]
        assert assigned_ids == [
        ]  # pool contained resources before any were assigned
Esempio n. 6
0
    def test_create_vm_pool_with_null_pool_name(self, proxy, cloud_account):
        '''Tests that a vm pool cannot be created without a name

        Arguments:
            proxy         - a pytest fixture proxy to RwMcYang
            cloud_account - a pytest fixture for the cloud account

        Asserts:
            Cloud account has a name
            rift.auto.proxy.ProxyRequestError is raised

        '''
        assert cloud_account.name is not None
        with pytest.raises(TypeError):
            pool_config = RwMcYang.VmPool(
                name=None,
                cloud_account=cloud_account.name,
                dynamic_scaling=True,
            )
Esempio n. 7
0
    def test_delete_cloud_account_with_vm_pool_with_vm_resources(
            self, proxy, cloud_account, vm_pool_name):
        '''Tests that a cloud account cannot be deleted if it has a vm pool

        Arguments:
            proxy              - a pytest fixture proxy to RwMcYang
            cloud_account_name - a pytest fixture for the cloud account name
            vm_pool_name       - a pytest fixture for the primary vm pool name

        Asserts:
            A cloud account exists for the cloud_account_name
            Newly configured vm pool has no resources assigned to it
            Cloud account has available resources
            VM pool has has available resources
            Cloud account and vm pool agree on available resources
            Configured resource is reflected as assigned in operational data
            post assignment
            rift.auto.proxy.ProxyRequestError is raised

        '''
        xpath = "/cloud-account/account[name='%s']" % cloud_account.name
        cloud_account = proxy.get(xpath)
        assert cloud_account is not None

        pool_config = RwMcYang.VmPool(
            name=vm_pool_name,
            cloud_account=cloud_account.name,
            dynamic_scaling=True,
        )
        proxy.create_config('/vm-pool/pool', pool_config)
        pool = proxy.get("/vm-pool/pool[name='%s']" % vm_pool_name)
        assigned_ids = [vm.id for vm in pool.assigned]
        assert len(assigned_ids
                   ) == 0  # pool contained resources before any were assigned

        account = proxy.get("/cloud-account/account[name='%s']" %
                            cloud_account.name)
        cloud_vm_ids = [vm.id for vm in account.resources.vm]
        assert len(cloud_vm_ids) >= 1

        pool = proxy.get("/vm-pool/pool[name='%s']" % vm_pool_name)
        available_ids = [vm.id for vm in pool.available]
        assert len(available_ids) >= 1  # Assert pool has available resources
        # Assert not split brain
        assert set(cloud_vm_ids).difference(set(available_ids)) == set([])

        pool_config = RwMcYang.VmPool.from_dict({
            'name':
            vm_pool_name,
            'cloud_account':
            cloud_account.name,
            'assigned': [{
                'id': available_ids[0]
            }]
        })
        proxy.replace_config("/vm-pool/pool[name='%s']" % vm_pool_name,
                             pool_config)
        pool = proxy.get("/vm-pool/pool[name='%s']" % vm_pool_name)
        assigned_ids = [vm.id for vm in pool.assigned]
        assert available_ids[
            0] in assigned_ids  # Configured resource shows as assigned

        xpath = "/cloud-account/account[name='%s']" % cloud_account.name
        with pytest.raises(ProxyRequestError):
            proxy.delete_config(xpath)