def testGettingHelpfulErrorMessageWithBaseclassRelationship(): """ Error messages for object.fromHash should be helpful. If the creation of a new object from a hash fails the resulting error message should show what required attributes are missing. """ try: ProductDependency.fromHash({ "productAction": "setup", "requirementType": "after", "requiredInstallationStatus": "installed", "requiredProductId": "mshotfix", "productId": "msservicepack" # The following attributes are missing: # * productVersion # * packageVersion }) assert False, 'Should not get here.' except TypeError as typo: print(u"Error is: {0!r}".format(typo)) assert u'__init__() takes at least 6 arguments (6 given)' not in str( typo) assert 'productVersion' in str(typo) assert 'packageVersion' in str(typo)
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'
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)
def testAlgorithm1SortingWithAfterSetupDependency(): renameClient = LocalbootProduct.fromHash({ "priority": 0, "packageVersion": "2", "productVersion": "1.0", "id": "renameopsiclient", }) winDomain = LocalbootProduct.fromHash({ "priority": 20, "packageVersion": "6", "productVersion": "1.0", "id": "windomain", }) productDep = ProductDependency.fromHash({ "productAction": "setup", "requirementType": "after", "productVersion": "1.0", "requiredProductId": "windomain", "requiredAction": "setup", "packageVersion": "6", "productId": "renameopsiclient" }) results = SharedAlgorithm.generateProductSequence_algorithm1( [winDomain, renameClient], [productDep]) first, second = results assert renameClient.id == first assert winDomain.id == second
def testAlgorithm1SortingWithDifferentPriorities(): msServicePack = LocalbootProduct.fromHash({ "priority": 0, "packageVersion": "5", "productVersion": "xpsp3", "id": "msservicepack" }) msHotFix = LocalbootProduct.fromHash({ "priority": 80, "packageVersion": "1", "productVersion": "201305", "id": "mshotfix" }) productDep = ProductDependency.fromHash({ "productAction": "setup", "requirementType": "after", "requiredInstallationStatus": "installed", "productVersion": "xpsp3", "requiredProductId": "mshotfix", "packageVersion": "5", "productId": "msservicepack" }) results = SharedAlgorithm.generateProductSequence_algorithm1( [msServicePack, msHotFix], [productDep]) first, second = results assert msServicePack.id == first assert msHotFix.id == second
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
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])
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
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()
def getDependenciesWithCrossingPriority(): ''' The sysessential dependency tries to move the product ultravnc to \ front in contradiction to priority ''' dependencies, products = getDependencies() sysessential = _getProductWithId(products, 'sysessential') ultravnc = _getProductWithId(products, 'ultravnc') sysessentialDependency1 = ProductDependency( productId=sysessential.id, productVersion=sysessential.productVersion, packageVersion=sysessential.packageVersion, productAction='setup', requiredProductId=ultravnc.id, requiredProductVersion=ultravnc.productVersion, requiredPackageVersion=ultravnc.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before') dependencies.append(sysessentialDependency1) return dependencies, products
def getCircularDepedencies(): ''' This creates a circular dependency. The testcase is that ultravnc depends on javavm, javavm on firefox and, now added, firefox on ultravnc. ''' dependencies, products = getDependencies() firefox = _getProductWithId(products, 'firefox') ultravnc = _getProductWithId(products, 'ultravnc') dependencies.append( ProductDependency(productId=firefox.id, productVersion=firefox.productVersion, packageVersion=firefox.packageVersion, productAction='setup', requiredProductId=ultravnc.id, requiredProductVersion=ultravnc.productVersion, requiredPackageVersion=ultravnc.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before')) return dependencies, products
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))
def getDependencies(): products = getAvailableProducts() flashplayer = _getProductWithId(products, 'flashplayer') firefox = _getProductWithId(products, 'firefox') javavm = _getProductWithId(products, 'javavm') jedit = _getProductWithId(products, 'jedit') ultravnc = _getProductWithId(products, 'ultravnc') flashplayerDependency1 = ProductDependency( productId=flashplayer.id, productVersion=flashplayer.productVersion, packageVersion=flashplayer.packageVersion, productAction='setup', requiredProductId=firefox.id, requiredProductVersion=firefox.productVersion, requiredPackageVersion=firefox.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before') javavmDependency1 = ProductDependency( productId=javavm.id, productVersion=javavm.productVersion, packageVersion=javavm.packageVersion, productAction='setup', requiredProductId=firefox.id, requiredProductVersion=firefox.productVersion, requiredPackageVersion=firefox.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before') jeditDependency1 = ProductDependency( productId=jedit.id, productVersion=jedit.productVersion, packageVersion=jedit.packageVersion, productAction='setup', requiredProductId=javavm.id, requiredProductVersion=javavm.productVersion, requiredPackageVersion=javavm.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before') ultravncDependency1 = ProductDependency( productId=ultravnc.id, productVersion=ultravnc.productVersion, packageVersion=ultravnc.packageVersion, productAction='setup', requiredProductId=javavm.id, requiredProductVersion=javavm.productVersion, requiredPackageVersion=javavm.packageVersion, requiredAction=None, requiredInstallationStatus='installed', requirementType='before') dependencies = [ flashplayerDependency1, javavmDependency1, jeditDependency1, ultravncDependency1 ] return dependencies, products
def testCreatingOrderWithImpossibleDependenciesFails(productSequenceAlgorithm): products = [{ "setupScript": "setup.ins", "name": "firefox-sequ", "priority": 0, "packageVersion": "1", "productVersion": "1.0", "id": "firefox-sequ", }, { "setupScript": "setup.ins", "uninstallScript": "unsetup.ins", "name": "flashplayer-sequ", "priority": 0, "packageVersion": "1", "productVersion": "1.0", "id": "flashplayer-sequ", }, { "setupScript": "setup.ins", "uninstallScript": "unsetup.ins", "name": "javavm-sequ", "priority": 0, "packageVersion": "1", "productVersion": "1.0", "id": "javavm-sequ", }, { "setupScript": "setup.ins", "name": "jedit-sequ", "priority": 0, "packageVersion": "1", "productVersion": "1.0", "id": "jedit-sequ", }, { "setupScript": "setup.ins", "uninstallScript": "unsetup.ins", "name": "sysessential-sequ", "priority": 55, "packageVersion": "1", "productVersion": "1.0", "id": "sysessential-sequ", }, { "setupScript": "setup.ins", "uninstallScript": "unsetup.ins", "name": "ultravnc-sequ", "priority": 0, "packageVersion": "1", "productVersion": "1.0", "id": "ultravnc-sequ", }] deps = [{ "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "ultravnc-sequ", "packageVersion": "1", "productId": "firefox-sequ" }, { "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "firefox-sequ", "packageVersion": "1", "productId": "flashplayer-sequ" }, { "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "firefox-sequ", "packageVersion": "1", "productId": "javavm-sequ" }, { "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "javavm-sequ", "packageVersion": "1", "productId": "jedit-sequ" }, { "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "ultravnc-sequ", "packageVersion": "1", "productId": "sysessential-sequ" }, { "ident": "ultravnc-sequ;1.0;1;setup;javavm-sequ", "productAction": "setup", "requirementType": "before", "requiredInstallationStatus": "installed", "productVersion": "1.0", "requiredProductId": "javavm-sequ", "packageVersion": "1", "productId": "ultravnc-sequ" }] products = [LocalbootProduct.fromHash(h) for h in products] deps = [ProductDependency.fromHash(h) for h in deps] with pytest.raises(OpsiProductOrderingError): try: productSequenceAlgorithm(products, deps) except OpsiProductOrderingError as error: raise error errormessage = forceUnicode(error) assert 'firefox-sequ' in errormessage assert 'javavm-sequ' in errormessage assert 'ultravnc-sequ' in errormessage