コード例 #1
0
def testSetProductActionRequestWithDependenciesWithDependencyRequestingAction(backendManager, installationStatus, actionRequest):
	client, depot = createClientAndDepot(backendManager)

	jedit = LocalbootProduct('jedit', '1.0', '1.0')
	javavm = LocalbootProduct('javavm', '1.0', '1.0')
	backendManager.product_createObjects([jedit, javavm])

	prodDependency = ProductDependency(
		productId=jedit.id,
		productVersion=jedit.productVersion,
		packageVersion=jedit.packageVersion,
		productAction='setup',
		requiredProductId=javavm.id,
		requiredAction='setup',
	)
	backendManager.productDependency_createObjects([prodDependency])

	jeditOnDepot = ProductOnDepot(
		productId=jedit.id,
		productType=jedit.getType(),
		productVersion=jedit.productVersion,
		packageVersion=jedit.packageVersion,
		depotId=depot.id,
	)
	javavmOnDepot = ProductOnDepot(
		productId=javavm.id,
		productType=javavm.getType(),
		productVersion=javavm.productVersion,
		packageVersion=javavm.packageVersion,
		depotId=depot.id,
	)
	backendManager.productOnDepot_createObjects([jeditOnDepot, javavmOnDepot])

	if installationStatus:
		poc = ProductOnClient(
			clientId=client.id,
			productId=javavm.id,
			productType=javavm.getType(),
			productVersion=javavm.productVersion,
			packageVersion=javavm.packageVersion,
			installationStatus=installationStatus,
			actionResult='successful'
		)

		backendManager.productOnClient_createObjects([poc])

	backendManager.setProductActionRequestWithDependencies('jedit', client.id, actionRequest)

	productsOnClient = backendManager.productOnClient_getObjects()
	assert 2 == len(productsOnClient)

	for poc in productsOnClient:
		if poc.productId == 'javavm':
			productThatShouldBeSetup = poc
			break
	else:
		raise ValueError('Could not find a product "{0}" on the client.'.format('already_installed'))

	assert productThatShouldBeSetup.productId == 'javavm'
	assert productThatShouldBeSetup.actionRequest == actionRequest
コード例 #2
0
def testGettingKioskInfoFromDifferentDepot(backendManager, client, depot,
                                           anotherDepot):
    backendManager.host_createObjects([client, depot, anotherDepot])

    products = list(createProducts(10))
    backendManager.product_createObjects(products)

    expectedProducts = set()
    for index, product in enumerate(products):
        pod = ProductOnDepot(
            productId=product.id,
            productType=product.getType(),
            productVersion=product.getProductVersion(),
            packageVersion=product.getPackageVersion(),
            depotId=depot.id,
        )
        backendManager.productOnDepot_createObjects([pod])

        if index % 2 == 0:
            # Assign every second product to the second depot
            pod.depotId = anotherDepot.id
            backendManager.productOnDepot_createObjects([pod])
            expectedProducts.add(product.id)

    productGroup = ProductGroup(id=u'my product group')
    backendManager.group_createObjects([productGroup])

    for product in products:
        groupAssignment = ObjectToGroup(groupType=productGroup.getType(),
                                        groupId=productGroup.id,
                                        objectId=product.id)
        backendManager.objectToGroup_createObjects([groupAssignment])

    basicConfigs = [
        UnicodeConfig(
            id=u'software-on-demand.product-group-ids',
            defaultValues=[productGroup.id],
            multiValue=True,
        ),
        UnicodeConfig(id=u'clientconfig.depot.id',
                      description=u'Depotserver to use',
                      possibleValues=[],
                      defaultValues=[depot.id]),
    ]
    backendManager.config_createObjects(basicConfigs)

    # Assign client to second depot
    backendManager.configState_create(u'clientconfig.depot.id',
                                      client.id,
                                      values=[anotherDepot.id])
    assert backendManager.getDepotId(client.id) == anotherDepot.id

    results = backendManager.getKioskProductInfosForClient(client.id)
    assert isinstance(results, list)

    for result in results:
        assert result['productId'] in expectedProducts

    assert len(results) == 5
コード例 #3
0
def fillBackend(backend):
	client, depot = createClientAndDepot(backend)

	firstProduct = LocalbootProduct('to_install', '1.0', '1.0')
	secondProduct = LocalbootProduct('already_installed', '1.0', '1.0')

	prodDependency = ProductDependency(
		productId=firstProduct.id,
		productVersion=firstProduct.productVersion,
		packageVersion=firstProduct.packageVersion,
		productAction='setup',
		requiredProductId=secondProduct.id,
		# requiredProductVersion=secondProduct.productVersion,
		# requiredPackageVersion=secondProduct.packageVersion,
		requiredAction='setup',
		requiredInstallationStatus='installed',
		requirementType='after'
	)

	backend.product_createObjects([firstProduct, secondProduct])
	backend.productDependency_createObjects([prodDependency])

	poc = ProductOnClient(
		clientId=client.id,
		productId=firstProduct.id,
		productType=firstProduct.getType(),
		productVersion=firstProduct.productVersion,
		packageVersion=firstProduct.packageVersion,
		installationStatus='installed',
		actionResult='successful'
	)

	backend.productOnClient_createObjects([poc])

	firstProductOnDepot = ProductOnDepot(
		productId=firstProduct.id,
		productType=firstProduct.getType(),
		productVersion=firstProduct.productVersion,
		packageVersion=firstProduct.packageVersion,
		depotId=depot.getId(),
		locked=False
	)

	secondProductOnDepot = ProductOnDepot(
		productId=secondProduct.id,
		productType=secondProduct.getType(),
		productVersion=secondProduct.productVersion,
		packageVersion=secondProduct.packageVersion,
		depotId=depot.getId(),
		locked=False
	)

	backend.productOnDepot_createObjects([firstProductOnDepot, secondProductOnDepot])
コード例 #4
0
def testSetProductActionRequestWithDependenciesWithOnce(backendManager):
	client, depot = createClientAndDepot(backendManager)

	masterProduct = LocalbootProduct('master', '3', '1.0')
	prodWithSetup = LocalbootProduct('reiter', '1.0', '1.0')
	prodWithOnce = LocalbootProduct('mania', '1.0', '1.0')
	backendManager.product_createObjects([masterProduct, prodWithOnce, prodWithSetup])

	prodOnceDependency = ProductDependency(
		productId=masterProduct.id,
		productVersion=masterProduct.productVersion,
		packageVersion=masterProduct.packageVersion,
		productAction='once',
		requiredProductId=prodWithOnce.id,
		requiredAction='once',
		requirementType='after',
	)
	prodSetupDependency = ProductDependency(
		productId=masterProduct.id,
		productVersion=masterProduct.productVersion,
		packageVersion=masterProduct.packageVersion,
		productAction='once',
		requiredProductId=prodWithSetup.id,
		requiredAction='setup',
		requirementType='after',
	)
	backendManager.productDependency_createObjects([prodOnceDependency, prodSetupDependency])

	for prod in (masterProduct, prodWithOnce, prodWithSetup):
		pod = ProductOnDepot(
			productId=prod.id,
			productType=prod.getType(),
			productVersion=prod.productVersion,
			packageVersion=prod.packageVersion,
			depotId=depot.id,
		)
		backendManager.productOnDepot_createObjects([pod])

	backendManager.setProductActionRequestWithDependencies(masterProduct.id, 'backend-test-1.vmnat.local', "once")

	productsOnClient = backendManager.productOnClient_getObjects()
	assert 3 == len(productsOnClient)

	depOnce = None
	depSetup = None

	for poc in productsOnClient:
		if poc.productId == prodWithOnce.id:
			depOnce = poc
		elif poc.productId == prodWithSetup.id:
			depSetup = poc

	if not depOnce:
		raise ValueError('Could not find a product {0!r} on the client.'.format(prodWithOnce.id))
	if not depSetup:
		raise ValueError('Could not find a product {0!r} on the client.'.format(prodWithSetup.id))

	assert depOnce.actionRequest == 'once'
	assert depSetup.actionRequest == 'setup'
コード例 #5
0
def testSetProductActionRequestWithDependenciesHandlingMissingProductOnDepot(backendManager):
	"""
	setProductActionRequestWithDependencies should be able to handle
	cases where not all products are present on the depot.
	"""
	client, depot = createClientAndDepot(backendManager)

	masterProduct = LocalbootProduct('master', '3', '1.0')
	prodWithSetup = LocalbootProduct('reiter', '1.0', '1.0')
	backendManager.product_createObjects([masterProduct, prodWithSetup])

	prodSetupDependency = ProductDependency(
		productId=masterProduct.id,
		productVersion=masterProduct.productVersion,
		packageVersion=masterProduct.packageVersion,
		productAction='setup',
		requiredProductId=prodWithSetup.id,
		requiredAction='setup',
		requirementType='after',
	)
	brokenSetupDependency = ProductDependency(
		productId=masterProduct.id,
		productVersion=masterProduct.productVersion,
		packageVersion=masterProduct.packageVersion,
		productAction='setup',
		requiredProductId='missing_product',
		requiredAction='setup',
		requirementType='after',
	)

	backendManager.productDependency_createObjects([prodSetupDependency, brokenSetupDependency])

	for prod in (masterProduct, prodWithSetup):
		pod = ProductOnDepot(
			productId=prod.id,
			productType=prod.getType(),
			productVersion=prod.productVersion,
			packageVersion=prod.packageVersion,
			depotId=depot.id,
		)
		backendManager.productOnDepot_createObjects([pod])

	backendManager.setProductActionRequestWithDependencies(masterProduct.id, client.id, "setup")

	productsOnClient = backendManager.productOnClient_getObjects()

	# Neither master nor dependencies are set to setup
	# product 'reiter' could be set to setup depending on the order in
	# which products are processed in the backend.
	# product 'master' will not be set to setup because it is set to
	# 'none' through OPSI.SharedAlgorithm.
	assert len(productsOnClient) <= 1

	for poc in productsOnClient:
		if poc.productId == 'reiter':
			assert poc.actionRequest == 'setup'
		else:
			raise RuntimeError("Unexpected product: %s" % poc)
コード例 #6
0
def testCacheDataCollectionWithPxeConfigTemplate(backendManager, client,
                                                 depot):
    """
    Collection of caching data with a product with pxeConfigTemplate.
    """
    backendManager.host_createObjects([client, depot])

    backendManager.config_createObjects([
        UnicodeConfig(
            id=u'opsi-linux-bootimage.append',
            possibleValues=[
                u'acpi=off', u'irqpoll', u'noapic', u'pci=nomsi',
                u'vga=normal', u'reboot=b'
            ],
            defaultValues=[u''],
        ),
        UnicodeConfig(
            id=u'clientconfig.configserver.url',
            description=u'URL(s) of opsi config service(s) to use',
            possibleValues=[u'https://%s:4447/rpc' % depot.id],
            defaultValues=[u'https://%s:4447/rpc' % depot.id],
        ),
        UnicodeConfig(id=u'clientconfig.depot.id',
                      description=u'Depotserver to use',
                      possibleValues=[],
                      defaultValues=[depot.id])
    ])

    product = NetbootProduct('mytest86',
                             productVersion=1,
                             packageVersion=1,
                             pxeConfigTemplate='scaredOfNothing')
    backendManager.product_insertObject(product)

    productOnDepot = ProductOnDepot(productId=product.getId(),
                                    productType=product.getType(),
                                    productVersion=product.getProductVersion(),
                                    packageVersion=product.getPackageVersion(),
                                    depotId=depot.id)
    backendManager.productOnDepot_createObjects([productOnDepot])

    poc = ProductOnClient(product.id,
                          product.getType(),
                          client.id,
                          actionRequest="setup")
    backendManager.productOnClient_insertObject(poc)

    with patchAddress(fqdn=depot.id):
        backend = OpsiPXEConfdBackend(context=backendManager)

        data = backend._collectDataForUpdate(client.id, depot.id)

        assert data
        assert data['product'][
            'pxeConfigTemplate'] == product.pxeConfigTemplate
コード例 #7
0
def testSetProductActionRequestWithDependenciesUpdateOnlyNeededObjects(backendManager):
	client, depot = createClientAndDepot(backendManager)

	expectedModificationTime = '2017-02-07 08:50:21'

	masterProduct = LocalbootProduct('master', '3', '1.0')
	prodWithSetup = LocalbootProduct('reiter', '1.0', '1.0')
	prodWithNoDep = LocalbootProduct('nicht_anfassen', '1.0', '1.0')
	backendManager.product_createObjects([masterProduct, prodWithNoDep, prodWithSetup])

	prodSetupDependency = ProductDependency(
		productId=masterProduct.id,
		productVersion=masterProduct.productVersion,
		packageVersion=masterProduct.packageVersion,
		productAction='setup',
		requiredProductId=prodWithSetup.id,
		requiredAction='setup',
		requirementType='after',
	)
	backendManager.productDependency_createObjects([prodSetupDependency])

	for prod in (masterProduct, prodWithNoDep, prodWithSetup):
		pod = ProductOnDepot(
			productId=prod.id,
			productType=prod.getType(),
			productVersion=prod.productVersion,
			packageVersion=prod.packageVersion,
			depotId=depot.id,
		)
		backendManager.productOnDepot_createObjects([pod])

	poc = ProductOnClient(
		clientId=client.id,
		productId=prodWithNoDep.id,
		productType=prodWithNoDep.getType(),
		productVersion=prodWithNoDep.productVersion,
		packageVersion=prodWithNoDep.packageVersion,
		installationStatus='installed',
		actionRequest=None,
		modificationTime=expectedModificationTime,
		actionResult='successful'
	)

	backendManager.productOnClient_createObjects([poc])

	backendManager.setProductActionRequestWithDependencies(masterProduct.id, client.id, "setup")

	productsOnClient = backendManager.productOnClient_getObjects()
	assert 3 == len(productsOnClient)

	for poc in productsOnClient:
		if poc.productId == 'nicht_anfassen':
			assert poc.modificationTime != expectedModificationTime
コード例 #8
0
def testSetProductActionRequestForHostGroup(backendManager):
    testGroup = HostGroup(id='host_group_1')

    client1 = OpsiClient(id='client1.test.invalid')
    client2 = OpsiClient(id='client2.test.invalid')

    client1ToGroup = ObjectToGroup(testGroup.getType(), testGroup.id,
                                   client1.id)
    client2ToGroup = ObjectToGroup(testGroup.getType(), testGroup.id,
                                   client2.id)

    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    product2 = LocalbootProduct(
        id='product2',
        name=u'Product 2',
        productVersion='2.0',
        packageVersion='test',
        setupScript="setup.ins",
    )

    prodOnDepot = ProductOnDepot(productId=product2.getId(),
                                 productType=product2.getType(),
                                 productVersion=product2.getProductVersion(),
                                 packageVersion=product2.getPackageVersion(),
                                 depotId=depot.getId())

    backendManager.host_insertObject(client1)
    backendManager.host_insertObject(client2)
    backendManager.host_insertObject(depot)
    backendManager.group_insertObject(testGroup)
    backendManager.objectToGroup_createObjects(
        [client1ToGroup, client2ToGroup])
    backendManager.config_create(u'clientconfig.depot.id')
    backendManager.configState_create(u'clientconfig.depot.id',
                                      client1.getId(),
                                      values=[depot.getId()])
    backendManager.configState_create(u'clientconfig.depot.id',
                                      client2.getId(),
                                      values=[depot.getId()])
    backendManager.product_insertObject(product2)
    backendManager.productOnDepot_insertObject(prodOnDepot)

    backendManager.setProductActionRequestForHostGroup('host_group_1',
                                                       'product2', 'setup')

    pocs = backendManager.productOnClient_getObjects()
    assert pocs
    assert len(pocs) == 2

    for poc in backendManager.productOnClient_getObjects():
        assert poc.productId == product2.getId()
        assert poc.clientId in (client1.id, client2.id)
コード例 #9
0
def testCleaninUpProducts(cleanableDataBackend):
    productIdToClean = 'dissection'

    prod1 = LocalbootProduct(productIdToClean, 1, 1)
    prod12 = LocalbootProduct(productIdToClean, 1, 2)
    prod13 = LocalbootProduct(productIdToClean, 1, 3)
    prod2 = LocalbootProduct(productIdToClean + '2', 2, 1)
    prod3 = LocalbootProduct('unhallowed', 3, 1)
    prod32 = LocalbootProduct('unhallowed', 3, 2)

    products = [prod1, prod12, prod13, prod2, prod3, prod32]
    for p in products:
        cleanableDataBackend.product_insertObject(p)

    configServer, depotServer, _ = fillBackendWithHosts(cleanableDataBackend)
    depot = depotServer[0]

    pod1 = ProductOnDepot(prod13.id, prod13.getType(), prod13.productVersion,
                          prod13.packageVersion, configServer.id)
    pod1d = ProductOnDepot(prod13.id, prod13.getType(), prod13.productVersion,
                           prod13.packageVersion, depot.id)
    pod2 = ProductOnDepot(prod2.id, prod2.getType(), prod2.productVersion,
                          prod2.packageVersion, depot.id)
    pod3 = ProductOnDepot(prod3.id, prod3.getType(), prod3.productVersion,
                          prod3.packageVersion, depot.id)

    for pod in [pod1, pod1d, pod2, pod3]:
        cleanableDataBackend.productOnDepot_insertObject(pod)

    cleanUpProducts(cleanableDataBackend)

    products = cleanableDataBackend.product_getObjects(id=productIdToClean)
    assert len(products) == 1

    product = products[0]
    assert product.id == productIdToClean

    allProducts = cleanableDataBackend.product_getObjects()
    assert len(allProducts) == 3  # prod13, prod2, prod3
コード例 #10
0
def testDoNotDuplicateProducts(backendManager, client, depot):
    backendManager.host_createObjects([client, depot])

    products = list(createProducts(10))
    backendManager.product_createObjects(products)

    for product in products:
        pod = ProductOnDepot(
            productId=product.id,
            productType=product.getType(),
            productVersion=product.getProductVersion(),
            packageVersion=product.getPackageVersion(),
            depotId=depot.id,
        )
        backendManager.productOnDepot_createObjects([pod])

    productGroupIds = set()
    for step in range(1, 4):
        productGroup = ProductGroup(id=u'group {0}'.format(step))
        backendManager.group_createObjects([productGroup])
        productGroupIds.add(productGroup.id)

        for product in products[::step]:
            groupAssignment = ObjectToGroup(groupType=productGroup.getType(),
                                            groupId=productGroup.id,
                                            objectId=product.id)
            backendManager.objectToGroup_createObjects([groupAssignment])

    basicConfigs = [
        UnicodeConfig(
            id=u'software-on-demand.product-group-ids',
            defaultValues=list(productGroupIds),
            multiValue=True,
        ),
        UnicodeConfig(id=u'clientconfig.depot.id',
                      description=u'Depotserver to use',
                      possibleValues=[],
                      defaultValues=[depot.id]),
    ]
    backendManager.config_createObjects(basicConfigs)

    result = backendManager.getKioskProductInfosForClient(client.id)
    assert isinstance(result, list)
    assert len(result) == len(products)
コード例 #11
0
        def lockProduct(backend, product, depotId, forceInstallation):
            productId = product.getId()
            logger.debug("Checking for locked product '{}' on depot '{}'",
                         productId, depotId)
            productOnDepots = backend.productOnDepot_getObjects(
                depotId=depotId, productId=productId)
            try:
                if productOnDepots[0].getLocked():
                    logger.notice(
                        u"Product '{0}' currently locked on depot '{1}'",
                        productId, depotId)
                    if not forceInstallation:
                        raise BackendTemporaryError(
                            u"Product '{}' currently locked on depot '{}'".
                            format(productId, depotId))
                    logger.warning(u"Installation of locked product forced")
            except IndexError:
                pass

            logger.notice(u"Locking product '{0}' on depot '{1}'", productId,
                          depotId)
            productOnDepot = ProductOnDepot(
                productId=productId,
                productType=product.getType(),
                productVersion=product.getProductVersion(),
                packageVersion=product.getPackageVersion(),
                depotId=depotId,
                locked=True)
            logger.info(u"Creating product on depot {0}", productOnDepot)
            backend.productOnDepot_createObjects(productOnDepot)

            try:
                yield productOnDepot
            except Exception as err:
                logger.warning(
                    "Installation error. Not unlocking product '{}' on depot '{}'.",
                    productId, depotId)
                raise err

            logger.notice(u"Unlocking product '{0}' {1}-{2} on depot '{3}'",
                          productOnDepot.getProductId(),
                          productOnDepot.getProductVersion(),
                          productOnDepot.getPackageVersion(), depotId)
            productOnDepot.setLocked(False)
            backend.productOnDepot_updateObject(productOnDepot)
コード例 #12
0
def testDeleteProductDependency(backendManager):
    firstProduct = LocalbootProduct('prod', '1.0', '1.0')
    secondProduct = LocalbootProduct('dependency', '1.0', '1.0')
    backendManager.product_insertObject(firstProduct)
    backendManager.product_insertObject(secondProduct)

    prodDependency = ProductDependency(
        productId=firstProduct.id,
        productVersion=firstProduct.productVersion,
        packageVersion=firstProduct.packageVersion,
        productAction='setup',
        requiredProductId=secondProduct.id,
        requiredAction='setup',
        requirementType='after')
    backendManager.productDependency_insertObject(prodDependency)

    depots = getDepotServers()
    depot = depots[0]
    backendManager.host_insertObject(depot)

    productOnDepot = ProductOnDepot(
        productId=firstProduct.getId(),
        productType=firstProduct.getType(),
        productVersion=firstProduct.getProductVersion(),
        packageVersion=firstProduct.getPackageVersion(),
        depotId=depot.id,
        locked=False)
    backendManager.productOnDepot_createObjects([productOnDepot])

    assert backendManager.productDependency_getObjects()

    backendManager.deleteProductDependency(
        firstProduct.id,
        "",
        secondProduct.id,
        requiredProductClassId="unusedParam",
        requirementType="unused")

    assert not backendManager.productDependency_getObjects()
コード例 #13
0
def testInstallingWithLockedProduct(depotserverBackend, depotServerFQDN,
                                    testPackageFile, forceInstallation,
                                    depotDirectory):
    product = LocalbootProduct(
        id='testingproduct',
        productVersion=23,
        packageVersion=41  # One lower than from the package file.
    )
    depotserverBackend.product_insertObject(product)

    lockedProductOnDepot = ProductOnDepot(
        productId=product.getId(),
        productType=product.getType(),
        productVersion=product.getProductVersion(),
        packageVersion=product.getPackageVersion(),
        depotId=depotServerFQDN,
        locked=True)
    depotserverBackend.productOnDepot_createObjects(lockedProductOnDepot)

    if not forceInstallation:
        with pytest.raises(BackendError):
            depotserverBackend.depot_installPackage(testPackageFile)

        # Checking that the package version does not get changed
        pod = depotserverBackend.productOnDepot_getObjects(
            productId=product.getId(), depotId=depotServerFQDN)[0]
        assert pod.locked is True
        assert '23' == pod.productVersion
        assert '41' == pod.packageVersion
    else:
        depotserverBackend.depot_installPackage(testPackageFile, force=True)

        pod = depotserverBackend.productOnDepot_getObjects(
            productId=product.getId(), depotId=depotServerFQDN)[0]
        assert pod.locked is False
        assert '23' == pod.productVersion
        assert '42' == pod.packageVersion

        assert isProductFolderInDepot(depotDirectory, product.id)
コード例 #14
0
def testCacheDataCollectionWithMultiplePxeConfigTemplates(
        backendManager, client, depot):
    """
    Testing what happens if each product version has a different pxe template.
    """
    backendManager.host_createObjects([client, depot])

    backendManager.config_createObjects([
        UnicodeConfig(
            id=u'opsi-linux-bootimage.append',
            possibleValues=[
                u'acpi=off', u'irqpoll', u'noapic', u'pci=nomsi',
                u'vga=normal', u'reboot=b'
            ],
            defaultValues=[u''],
        ),
        UnicodeConfig(
            id=u'clientconfig.configserver.url',
            description=u'URL(s) of opsi config service(s) to use',
            possibleValues=[u'https://%s:4447/rpc' % depot.id],
            defaultValues=[u'https://%s:4447/rpc' % depot.id],
        ),
        UnicodeConfig(id=u'clientconfig.depot.id',
                      description=u'Depotserver to use',
                      possibleValues=[],
                      defaultValues=[depot.id])
    ])

    oldProduct = NetbootProduct('mytest86',
                                productVersion=1,
                                packageVersion=1,
                                pxeConfigTemplate='old')
    backendManager.product_insertObject(oldProduct)
    newProduct = NetbootProduct(oldProduct.id,
                                productVersion=oldProduct.productVersion,
                                packageVersion=int(oldProduct.packageVersion) +
                                1,
                                pxeConfigTemplate='new')
    backendManager.product_insertObject(newProduct)

    # The following product exists but is not available on the depot.
    newerProduct = NetbootProduct(
        oldProduct.id,
        productVersion=oldProduct.productVersion,
        packageVersion=int(oldProduct.packageVersion) + 2,
        pxeConfigTemplate='new')
    backendManager.product_insertObject(newerProduct)

    productOnDepot = ProductOnDepot(
        productId=newProduct.getId(),
        productType=newProduct.getType(),
        productVersion=newProduct.getProductVersion(),
        packageVersion=newProduct.getPackageVersion(),
        depotId=depot.id)
    backendManager.productOnDepot_createObjects([productOnDepot])

    poc = ProductOnClient(oldProduct.id,
                          oldProduct.getType(),
                          client.id,
                          actionRequest="setup")
    backendManager.productOnClient_insertObject(poc)

    with patchAddress(fqdn=depot.id):
        backend = OpsiPXEConfdBackend(context=backendManager)

        data = backend._collectDataForUpdate(client.id, depot.id)

        assert data['product'][
            'pxeConfigTemplate'] == newProduct.pxeConfigTemplate
コード例 #15
0
def testGettingKioskInfoWithConfigStates(backendManager, client, depot,
                                         addConfigs):
    backendManager.host_createObjects([client, depot])

    products = list(createProducts(2))
    backendManager.product_createObjects(products)

    for product in products:
        pod = ProductOnDepot(
            productId=product.id,
            productType=product.getType(),
            productVersion=product.getProductVersion(),
            packageVersion=product.getPackageVersion(),
            depotId=depot.id,
        )
        backendManager.productOnDepot_createObjects([pod])

    productGroup = ProductGroup(id=u'my product group')
    backendManager.group_createObjects([productGroup])

    for product in products:
        groupAssignment = ObjectToGroup(groupType=productGroup.getType(),
                                        groupId=productGroup.id,
                                        objectId=product.id)
        backendManager.objectToGroup_createObjects([groupAssignment])

    dependency = ProductDependency(productId=products[0].id,
                                   requiredProductId=products[1].id,
                                   productVersion='1',
                                   packageVersion='1',
                                   productAction="setup",
                                   requiredAction="setup")
    backendManager.productDependency_createObjects([dependency])

    basicConfigs = [
        UnicodeConfig(
            id=u'software-on-demand.product-group-ids',
            defaultValues=[productGroup.id],
            multiValue=True,
        ),
        UnicodeConfig(id=u'clientconfig.depot.id',
                      description=u'Depotserver to use',
                      possibleValues=[],
                      defaultValues=[depot.id]),
    ]
    backendManager.config_createObjects(basicConfigs)

    result = backendManager.getKioskProductInfosForClient(
        clientId=client.id, addConfigs=addConfigs)

    if addConfigs:
        assert isinstance(result, dict)
        assert len(result) == 2

        assert len(result["configStates"]) == 1
        assert len(result['products']) == 2

        for item in result["products"]:
            if item["productId"] == products[0].id:
                assert len(item["requirements"]) == 1
                break
        else:
            raise RuntimeError("Did not find product with id {}".format(
                products[0].id))
    else:
        assert isinstance(result, list)
        assert len(result) == 2

        for item in result:
            assert isinstance(item, dict)
            if item["productId"] == products[0].id:
                assert len(item["requirements"]) == 1
                break
        else:
            raise RuntimeError("Did not find product with id {}".format(
                products[0].id))
コード例 #16
0
def testUpdateWhereInstalled(backendManager):
    backend = backendManager

    client_with_old_product = OpsiClient(id='clientwithold.test.invalid')
    client_with_current_product = OpsiClient(id='clientwithcurrent.test.invalid')
    client_without_product = OpsiClient(id='clientwithout.test.invalid')

    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    backend.host_createObjects([depot, client_with_old_product,
                                client_with_current_product,
                                client_without_product])

    old_product = LocalbootProduct('thunderheart', '1', '1')
    new_product = LocalbootProduct('thunderheart', '1', '2',
                                   updateScript='foo.opsiscript')

    backend.product_createObjects([old_product, new_product])

    assert not backend.updateWhereInstalled('thunderheart')

    poc = ProductOnClient(
        clientId=client_with_old_product.id,
        productId=old_product.id,
        productType=old_product.getType(),
        productVersion=old_product.productVersion,
        packageVersion=old_product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    poc2 = ProductOnClient(
        clientId=client_with_current_product.id,
        productId=new_product.id,
        productType=new_product.getType(),
        productVersion=new_product.productVersion,
        packageVersion=new_product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )

    backend.productOnClient_createObjects([poc, poc2])

    installedProductOnDepot = ProductOnDepot(
        productId=new_product.id,
        productType=new_product.getType(),
        productVersion=new_product.productVersion,
        packageVersion=new_product.packageVersion,
        depotId=depot.getId(),
        locked=False
    )

    backend.productOnDepot_createObjects([installedProductOnDepot])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )

    backend.config_createObjects(clientConfigDepotId)

    # Starting the checks
    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_without_product.id)
    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_old_product.id, actionRequest="setup")
    assert backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_current_product.id)

    clientIDs = backend.updateWhereInstalled('thunderheart')

    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_without_product.id)
    poc = backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_old_product.id)[0]
    assert "update" == poc.actionRequest
    poc = backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_current_product.id)[0]
    assert "update" == poc.actionRequest

    assert 2 == len(clientIDs)
    assert client_with_old_product.id in clientIDs
    assert client_with_current_product.id in clientIDs
コード例 #17
0
def test_selectProductOnClientWithDefault(extendedConfigDataBackend):
    client = OpsiClient(id='client.test.invalid')
    depot = OpsiDepotserver(id='depotserver1.test.invalid')
    extendedConfigDataBackend.host_createObjects([client, depot])

    poc = ProductOnClient(
        productId='product6',
        productType='LocalbootProduct',
        clientId=client.id,
        installationStatus='not_installed',
        actionRequest='setup'
    )
    extendedConfigDataBackend.productOnClient_createObjects(poc)

    prod6 = LocalbootProduct(
        id="product6",
        productVersion="1.0",
        packageVersion=1,
    )
    prod7 = LocalbootProduct(
        id='product7',
        name=u'Product 7',
        productVersion="1.0",
        packageVersion=1,
    )
    extendedConfigDataBackend.product_createObjects([prod6, prod7])

    installedProductOnDepot6 = ProductOnDepot(
        productId=prod6.id,
        productType=prod6.getType(),
        productVersion=prod6.productVersion,
        packageVersion=prod6.packageVersion,
        depotId=depot.getId(),
        locked=False
    )
    installedProductOnDepot7 = ProductOnDepot(
        productId=prod7.id,
        productType=prod7.getType(),
        productVersion=prod7.productVersion,
        packageVersion=prod7.packageVersion,
        depotId=depot.getId(),
        locked=False
    )
    extendedConfigDataBackend.productOnDepot_createObjects([
        installedProductOnDepot6,
        installedProductOnDepot7
    ])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )
    extendedConfigDataBackend.config_createObjects(clientConfigDepotId)

    with temporaryBackendOptions(extendedConfigDataBackend, addProductOnClientDefaults=True):
        productOnClients = [pocc.productId for pocc in
                            extendedConfigDataBackend.productOnClient_getObjects(
                                clientId=client.id,
                                productId=['product6', 'product7'])]

    productOnClients.sort()
    assert productOnClients == [u'product6', u'product7']
コード例 #18
0
def testUninstallWhereInstalled(backendManager):
    backend = backendManager
    client_with_product = OpsiClient(id='clientwith.test.invalid')
    client_without_product = OpsiClient(id='clientwithout.test.invalid')
    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    backend.host_createObjects([depot, client_with_product,
                                client_without_product])

    product = LocalbootProduct('thunderheart', '1', '1', uninstallScript='foo.bar')
    productWithoutScript = LocalbootProduct('installOnly', '1', '1')

    backend.product_createObjects([product, productWithoutScript])

    installedProductOnDepot = ProductOnDepot(
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        depotId=depot.id,
        locked=False
    )
    installedProductOnDepot2 = ProductOnDepot(
        productId=productWithoutScript.id,
        productType=productWithoutScript.getType(),
        productVersion=productWithoutScript.productVersion,
        packageVersion=productWithoutScript.packageVersion,
        depotId=depot.id,
        locked=False
    )

    backend.productOnDepot_createObjects([installedProductOnDepot,
                                          installedProductOnDepot2])

    assert not backend.uninstallWhereInstalled('thunderheart')

    poc = ProductOnClient(
        clientId=client_with_product.id,
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    pocWithoutScript = ProductOnClient(
        clientId=client_with_product.id,
        productId=productWithoutScript.id,
        productType=productWithoutScript.getType(),
        productVersion=productWithoutScript.productVersion,
        packageVersion=productWithoutScript.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    backend.productOnClient_createObjects([poc, pocWithoutScript])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )
    backend.config_createObjects(clientConfigDepotId)

    clientIDs = backend.uninstallWhereInstalled(product.id)

    assert 1 == len(clientIDs)
    pocAfter = backend.productOnClient_getObjects(productId=product.id, clientId=client_with_product.id)
    assert 1 == len(pocAfter)
    pocAfter = pocAfter[0]
    assert "uninstall" == pocAfter.actionRequest

    clientIDs = backend.uninstallWhereInstalled(productWithoutScript.id)
    assert 0 == len(clientIDs)
コード例 #19
0
def testSetupWhereInstalled(backendManager):
    backend = backendManager

    client_with_product = OpsiClient(id='clientwith.test.invalid')
    client_with_failed_product = OpsiClient(id='failedclient.test.invalid')
    client_without_product = OpsiClient(id='clientwithout.test.invalid')

    clients = set([client_with_product, client_without_product, client_with_failed_product])
    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    backend.host_createObjects([depot])
    backend.host_createObjects(clients)

    product = LocalbootProduct('thunderheart', '1', '1', setupScript='foo.bar')

    backend.product_createObjects([product])

    installedProductOnDepot = ProductOnDepot(
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        depotId=depot.id,
        locked=False
    )

    backend.productOnDepot_createObjects([installedProductOnDepot])

    assert not backend.setupWhereInstalled('thunderheart')

    poc = ProductOnClient(
        clientId=client_with_product.id,
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    pocFailed = ProductOnClient(
        clientId=client_with_failed_product.id,
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        installationStatus='unknown',
        actionResult='failed'
    )
    backend.productOnClient_createObjects([poc, pocFailed])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )

    backend.config_createObjects(clientConfigDepotId)

    for client in clients:
        clientDepotMappingConfigState = ConfigState(
            configId=u'clientconfig.depot.id',
            objectId=client.getId(),
            values=depot.getId()
        )

        backend.configState_createObjects(clientDepotMappingConfigState)

    clientIDs = backend.setupWhereInstalled(product.id)
    assert 1 == len(clientIDs)
    assert client_with_product.id == forceList(clientIDs)[0]

    assert not backend.productOnClient_getObjects(productId=product.id, clientId=client_without_product.id)

    pocAfter = backend.productOnClient_getObjects(productId=product.id, clientId=client_with_product.id)
    assert 1 == len(pocAfter)
    pocAfter = pocAfter[0]
    assert "setup" == pocAfter.actionRequest

    pocFailed = backend.productOnClient_getObjects(productId=product.id, clientId=client_with_failed_product.id)
    assert 1 == len(pocFailed)
    pocFailed = pocFailed[0]
    assert "setup" != pocFailed.actionRequest
    assert 'successful' == poc.actionResult
コード例 #20
0
def testSetActionRequestWhereOutdated(backendManager):
    backend = backendManager

    client_with_old_product = OpsiClient(id='clientwithold.test.invalid')
    client_with_current_product = OpsiClient(id='clientwithcurrent.test.invalid')
    client_without_product = OpsiClient(id='clientwithout.test.invalid')
    client_unknown_status = OpsiClient(id='clientunkown.test.invalid')
    clients = [client_with_old_product, client_with_current_product,
               client_without_product, client_unknown_status]

    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    backend.host_createObjects([depot, client_with_old_product,
                                client_with_current_product,
                                client_without_product, client_unknown_status])

    old_product = LocalbootProduct('thunderheart', '1', '1')
    new_product = LocalbootProduct('thunderheart', '1', '2')

    backend.product_createObjects([old_product, new_product])

    with pytest.raises(ValueError):
        backend.setActionRequestWhereOutdated('invalid', 'thunderheart')

    poc = ProductOnClient(
        clientId=client_with_old_product.id,
        productId=old_product.id,
        productType=old_product.getType(),
        productVersion=old_product.productVersion,
        packageVersion=old_product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    poc2 = ProductOnClient(
        clientId=client_with_current_product.id,
        productId=new_product.id,
        productType=new_product.getType(),
        productVersion=new_product.productVersion,
        packageVersion=new_product.packageVersion,
        installationStatus='installed',
        actionResult='successful'
    )
    poc3 = ProductOnClient(
        clientId=client_unknown_status.id,
        productId=old_product.id,
        productType=old_product.getType(),
        productVersion=old_product.productVersion,
        packageVersion=old_product.packageVersion,
        installationStatus='unknown',
    )

    backend.productOnClient_createObjects([poc, poc2, poc3])

    installedProductOnDepot = ProductOnDepot(
        productId=new_product.id,
        productType=new_product.getType(),
        productVersion=new_product.productVersion,
        packageVersion=new_product.packageVersion,
        depotId=depot.getId(),
        locked=False
    )

    backend.productOnDepot_createObjects([installedProductOnDepot])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )

    backend.config_createObjects(clientConfigDepotId)

    for client in clients:
        clientDepotMappingConfigState = ConfigState(
            configId=u'clientconfig.depot.id',
            objectId=client.getId(),
            values=depot.getId()
        )

        backend.configState_createObjects(clientDepotMappingConfigState)

    # Starting the checks
    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_without_product.id)
    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_old_product.id, actionRequest="setup")
    assert backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_current_product.id)
    assert backend.productOnClient_getObjects(productId=old_product.id, clientId=client_unknown_status.id, installationStatus='unknown')

    clientIDs = backend.setActionRequestWhereOutdated('setup', new_product.id)

    assert 1 == len(clientIDs)
    assert client_with_old_product.id, list(clientIDs)[0]
    assert not backend.productOnClient_getObjects(productId=new_product.id, clientId=client_without_product.id)
    poc = backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_old_product.id)[0]
    assert "setup" == poc.actionRequest

    poc = backend.productOnClient_getObjects(productId=new_product.id, clientId=client_with_current_product.id)[0]
    assert "setup" != poc.actionRequest

    poc = backend.productOnClient_getObjects(productId=old_product.id, clientId=client_unknown_status.id)[0]
    assert "setup" != poc.actionRequest
    assert "unknown" == poc.installationStatus
コード例 #21
0
def testSetupWhereFailed(backendManager):
    backend = backendManager

    client_with_failed_product = OpsiClient(id='clientwithcurrent.test.invalid')
    client_without_product = OpsiClient(id='clientwithout.test.invalid')

    depot = OpsiDepotserver(id='depotserver1.test.invalid')

    backend.host_createObjects([depot,
                                client_with_failed_product,
                                client_without_product])

    product = LocalbootProduct('thunderheart', '1', '1', setupScript='foo.bar')

    backend.product_createObjects([product])

    poc = ProductOnClient(
        clientId=client_with_failed_product.id,
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        actionResult='failed',
    )

    backend.productOnClient_createObjects([poc])

    installedProductOnDepot = ProductOnDepot(
        productId=product.id,
        productType=product.getType(),
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        depotId=depot.getId(),
        locked=False
    )

    backend.productOnDepot_createObjects([installedProductOnDepot])

    clientConfigDepotId = UnicodeConfig(
        id=u'clientconfig.depot.id',
        description=u'Depotserver to use',
        possibleValues=[],
        defaultValues=[depot.id]
    )

    backend.config_createObjects(clientConfigDepotId)

    for client in (client_with_failed_product, client_without_product):
        clientDepotMappingConfigState = ConfigState(
            configId=u'clientconfig.depot.id',
            objectId=client.getId(),
            values=depot.getId()
        )

        backend.configState_createObjects(clientDepotMappingConfigState)

    # Starting the checks
    assert not backend.productOnClient_getObjects(productId=product.id, clientId=client_without_product.id)
    assert backend.productOnClient_getObjects(productId=product.id, clientId=client_with_failed_product.id)

    clientIDs = backend.setupWhereFailed(product.id)

    assert 1 == len(clientIDs)
    poc = backend.productOnClient_getObjects(productId=product.id, clientId=client_with_failed_product.id)[0]
    assert "setup" == poc.actionRequest
    assert 'failed' == poc.actionResult