def testGetClientsWithActionRequest(backendManager, clients, param): for client in clients: backendManager.host_insertObject(client) testclient1 = OpsiClient(id='testclient1.test.invalid') backendManager.host_insertObject(testclient1) product1 = LocalbootProduct('product1', '1.0', '1') backendManager.product_insertObject(product1) product2 = LocalbootProduct('product2', '2.0', '1') backendManager.product_insertObject(product2) fillerProducts = [ LocalbootProduct("filler1", '1', '1'), LocalbootProduct("filler2", '2', '2'), LocalbootProduct("filler3", '3', '3'), ] for poc in fillerProducts: backendManager.product_insertObject(poc) # Skipping update because we search for this actionRequests = ['setup', 'uninstall', 'always', 'once', 'custom', 'none'] fillerPocs = [ ProductOnClient(productId=product.getId(), productType=product.getType(), clientId=client.getId(), installationStatus=random.choice( ['installed', 'not_installed', 'unknown']), actionRequest=random.choice(actionRequests), productVersion=product.getProductVersion(), packageVersion=product.getPackageVersion()) for client, product in itertools.product(clients, fillerProducts) ] relevantPocs = [ ProductOnClient(productId=product1.getId(), productType=product1.getType(), clientId=testclient1.getId(), installationStatus='installed', actionRequest='update', productVersion=product1.getProductVersion(), packageVersion=product1.getPackageVersion()), ProductOnClient(productId=product2.getId(), productType=product2.getType(), clientId=testclient1.getId(), installationStatus='unknown', actionRequest='update', productVersion=product2.getProductVersion(), packageVersion=product2.getPackageVersion()), ] for poc in fillerPocs + relevantPocs: backendManager.productOnClient_insertObject(poc) clientsToCheck = backendManager.getClientsWithActionRequest(param) assert len(clientsToCheck) == 1 assert clientsToCheck[0] == testclient1.id
def testGetClientsWithProductsWithSpecificStatus(backendManager, clients, desiredStatus, expectedClient): for client in clients: backendManager.host_insertObject(client) testclient1 = OpsiClient(id='testclient1.test.invalid') backendManager.host_insertObject(testclient1) testclient2 = OpsiClient(id='testclient2.test.invalid') backendManager.host_insertObject(testclient2) product1 = LocalbootProduct('product1', '1.0', '1') backendManager.product_insertObject(product1) product2 = LocalbootProduct('product2', '2.0', '1') backendManager.product_insertObject(product2) fillerProducts = [ LocalbootProduct("filler1", '1', '1'), LocalbootProduct("filler2", '2', '2'), LocalbootProduct("filler3", '3', '3'), ] for poc in fillerProducts: backendManager.product_insertObject(poc) fillerPocs = [ ProductOnClient(productId=product.getId(), productType=product.getType(), clientId=client.getId(), installationStatus=random.choice( ['installed', 'not_installed', 'unknown']), productVersion=product.getProductVersion(), packageVersion=product.getPackageVersion()) for client, product in itertools.product(clients, fillerProducts) ] relevantPocs = [ ProductOnClient(productId=product1.getId(), productType=product1.getType(), clientId=testclient2.getId(), installationStatus='installed', productVersion=product1.getProductVersion(), packageVersion=product1.getPackageVersion()), ProductOnClient(productId=product2.getId(), productType=product2.getType(), clientId=testclient1.getId(), installationStatus='unknown', productVersion=product2.getProductVersion(), packageVersion=product2.getPackageVersion()), ] for poc in fillerPocs + relevantPocs: backendManager.productOnClient_insertObject(poc) clientsToCheck = backendManager.getClientsWithProducts( [product1.id, product2.id], desiredStatus) assert len(clientsToCheck) == 1 assert clientsToCheck[0] == expectedClient
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)
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)
def testGetClientsWithProducts(backendManager, clients): for client in clients: backendManager.host_insertObject(client) testclient = random.choice(clients) dummyClient = random.choice([c for c in clients if c != testclient]) product = LocalbootProduct('product2', '2.0', 'test') backendManager.product_insertObject(product) fillerProducts = [ LocalbootProduct("filler1", '1', '1'), LocalbootProduct("filler2", '2', '2'), LocalbootProduct("filler3", '3', '3'), ] for poc in fillerProducts: backendManager.product_insertObject(poc) fillerProd = random.choice(fillerProducts) fillerProd2 = random.choice(fillerProducts) fillerPocs = [ ProductOnClient(productId=fillerProd.getId(), productType=fillerProd.getType(), clientId=dummyClient.getId(), installationStatus='installed', productVersion=fillerProd.getProductVersion(), packageVersion=fillerProd.getPackageVersion()), ProductOnClient(productId=fillerProd2.getId(), productType=fillerProd2.getType(), clientId=dummyClient.getId(), installationStatus='installed', productVersion=fillerProd2.getProductVersion(), packageVersion=fillerProd2.getPackageVersion()), ] relevantPoc = ProductOnClient(productId=product.getId(), productType=product.getType(), clientId=testclient.getId(), installationStatus='installed', productVersion=product.getProductVersion(), packageVersion=product.getPackageVersion()) for poc in fillerPocs + [relevantPoc]: backendManager.productOnClient_insertObject(poc) clientsToCheck = backendManager.getClientsWithProducts([product.id]) assert len(clientsToCheck) == 1 assert clientsToCheck[0] == testclient.id
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()