예제 #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 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
예제 #3
0
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
예제 #4
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])
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)
예제 #6
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
예제 #7
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
예제 #8
0
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()
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)
예제 #11
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']
예제 #12
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
예제 #13
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
예제 #14
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
예제 #15
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
예제 #16
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)