Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
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
Exemplo n.º 6
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])
Exemplo n.º 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
Exemplo n.º 8
0
def test_createProductOnClient(extendedConfigDataBackend):
    client = OpsiClient(id='client.test.invalid')
    extendedConfigDataBackend.host_createObjects(client)

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

    productOnClients = [poc for poc in
                        extendedConfigDataBackend.productOnClient_getObjects(clientId=client.id)
                        if poc.actionRequest == 'setup']

    assert [originalPoc] == productOnClients
Exemplo n.º 9
0
def test_selectProductOnClientsByWildcard(extendedConfigDataBackend):
    client = OpsiClient(id='client.test.invalid')
    extendedConfigDataBackend.host_createObjects(client)

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

    productOnClients = extendedConfigDataBackend.productOnClient_getObjects(
        clientId=client.id,
        productId='*6*'
    )
    assert productOnClients == [poc]
Exemplo n.º 10
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)
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
Exemplo n.º 12
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']
Exemplo n.º 13
0
def addActionRequest(productOnClientByProductId, productId, productDependenciesByProductId, availableProductsByProductId, addedInfo=None):
	logger.debug(u"Checking dependencies for product {0!r}, action {1!r}", productId, productOnClientByProductId[productId].actionRequest)
	addedInfo = addedInfo or {}

	poc = productOnClientByProductId[productId]
	if poc.actionRequest == 'none' or not productDependenciesByProductId.get(productId):
		return

	for dependency in productDependenciesByProductId[productId]:
		if dependency.productAction != poc.actionRequest:
			continue

		logger.debug(u"   need to check dependency to product {0!r}", dependency.requiredProductId)
		if dependency.requiredAction:
			logger.debug(
				u"   product {0!r} requires action {1.requiredAction!r} "
				u"of product {1.requiredProductId!r} "
				u"{1.requiredProductVersion!r}-{1.requiredPackageVersion!r} "
				u"on action {1.productAction!r}",
				productId,
				dependency
			)
		elif dependency.requiredInstallationStatus:
			logger.debug(
				u"   product {0!r} requires status "
				u"{1.requiredInstallationStatus!r} of "
				u"product {1.requiredProductId!r} "
				u"{1.requiredProductVersion!r}-{1.requiredPackageVersion!r} "
				u"on action {1.productAction!r}",
				productId,
				dependency
			)

		requiredAction = dependency.requiredAction
		installationStatus = 'not_installed'
		actionRequest = 'none'
		if dependency.requiredProductId in productOnClientByProductId:
			installationStatus = productOnClientByProductId[dependency.requiredProductId].installationStatus
			actionRequest = productOnClientByProductId[dependency.requiredProductId].actionRequest
		logger.debug(u"addActionRequest: requiredAction {0}", requiredAction)
		if not requiredAction:
			if dependency.requiredInstallationStatus == installationStatus:
				logger.debug(u"   required installation status {0!r} is fulfilled", dependency.requiredInstallationStatus)
				continue
			elif dependency.requiredInstallationStatus == 'installed':
				requiredAction = 'setup'
			elif dependency.requiredInstallationStatus == 'not_installed':
				requiredAction = 'uninstall'

		# An action is required => check if possible
		logger.debug(u"   need to set action {0!r} for product {1!r} to fulfill dependency", requiredAction, dependency.requiredProductId)

		setActionRequestToNone = False
		if dependency.requiredProductId not in availableProductsByProductId:
			logger.warning(u"   product {0!r} defines dependency to product {1!r}, which is not avaliable on depot", productId, dependency.requiredProductId)
			setActionRequestToNone = True
		elif dependency.requiredProductVersion is not None and dependency.requiredProductVersion != availableProductsByProductId[dependency.requiredProductId].productVersion:
			logger.warning(
				u"   product {0!r} defines dependency to product "
				u"{1.requiredProductId!r}, but product version "
				u"{1.requiredProductVersion!r} is not available",
				productId,
				dependency
			)
			setActionRequestToNone = True
		elif dependency.requiredPackageVersion is not None and dependency.requiredPackageVersion != availableProductsByProductId[dependency.requiredProductId].packageVersion:
			logger.warning(
				u"   product {0!r} defines dependency to product "
				u"{1.requiredProductId!r}, but package version "
				u"{1.requiredProductId!r} is not available",
				productId,
				dependency
			)
			setActionRequestToNone = True

		if setActionRequestToNone:
			logger.notice(u"   => setting action request for product {0!r} to 'none'!", productId)
			productOnClientByProductId[productId].actionRequest = 'none'
			continue

		if actionRequest == requiredAction:
			logger.debug(u"   => required action {0!r} is already set", requiredAction)
			continue
		elif actionRequest not in (None, 'none'):
			logger.debug(
				u"   => cannot fulfill dependency of product {0!r} to "
				u"product {1!r}: action {2!r} needed but action {3!r} "
				u"already set",
				productId,
				dependency.requiredProductId,
				requiredAction,
				actionRequest
			)
			continue

		if dependency.requiredProductId in addedInfo:
			logger.warning(u"   => Product dependency loop including product {} detected, skipping", productId)
			logger.debug(
				u"Circular dependency at {2}. Processed product: {0}"
				u"addedInfo: {1}",
				productId,
				addedInfo,
				dependency.requiredProductId
			)
			continue

		logger.info(u"   => adding action {0!r} for product {1!r}", requiredAction, dependency.requiredProductId)

		if dependency.requiredProductId not in productOnClientByProductId:
			productOnClientByProductId[dependency.requiredProductId] = ProductOnClient(
				productId=dependency.requiredProductId,
				productType=availableProductsByProductId[dependency.requiredProductId].getType(),
				clientId=poc.clientId,
				installationStatus=None,
				actionRequest=u'none',
			)

		addedInfo[dependency.requiredProductId] = {
			'addedForProduct': productId,
			'requiredAction': requiredAction,
			'requirementType': dependency.requirementType
		}
		productOnClientByProductId[dependency.requiredProductId].setActionRequest(requiredAction)

		addActionRequest(productOnClientByProductId, dependency.requiredProductId, productDependenciesByProductId, availableProductsByProductId, addedInfo)
Exemplo n.º 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
Exemplo n.º 15
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
Exemplo n.º 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
Exemplo n.º 17
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