Пример #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 testComparingTwoLocalbootProductsWithSameSettings():
    firstProduct = LocalbootProduct(
        id='product2',
        name=u'Product 2',
        productVersion='2.0',
        packageVersion='test',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        updateScript="update.ins",
        alwaysScript=None,
        onceScript=None,
        priority=0,
        description=None,
        advice="",
        productClassIds=['localboot-products'],
        windowsSoftwareIds=['{98723-7898adf2-287aab}', 'xxxxxxxx'])
    secondProduct = LocalbootProduct(
        id='product2',
        name=u'Product 2',
        productVersion='2.0',
        packageVersion='test',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        updateScript="update.ins",
        alwaysScript=None,
        onceScript=None,
        priority=0,
        description=None,
        advice="",
        productClassIds=['localboot-products'],
        windowsSoftwareIds=['xxxxxxxx', '{98723-7898adf2-287aab}'])

    assert firstProduct == secondProduct
Пример #3
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
Пример #4
0
def testSetProductActionRequestWithDependenciesWithOnce(backendManager):
	client, depot = createClientAndDepot(backendManager)

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

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

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

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

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

	depOnce = None
	depSetup = None

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

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

	assert depOnce.actionRequest == 'once'
	assert depSetup.actionRequest == 'setup'
Пример #5
0
def 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
Пример #6
0
def testSetProductActionRequestWithDependenciesHandlingMissingProductOnDepot(backendManager):
	"""
	setProductActionRequestWithDependencies should be able to handle
	cases where not all products are present on the depot.
	"""
	client, depot = createClientAndDepot(backendManager)

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

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

	backendManager.productDependency_createObjects([prodSetupDependency, brokenSetupDependency])

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

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

	productsOnClient = backendManager.productOnClient_getObjects()

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

	for poc in productsOnClient:
		if poc.productId == 'reiter':
			assert poc.actionRequest == 'setup'
		else:
			raise RuntimeError("Unexpected product: %s" % poc)
Пример #7
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])
Пример #8
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
Пример #9
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
Пример #10
0
def testWorkingWithSet():
	# Exactly one product because set is unordered.
	obj = set([
		LocalbootProduct(
			id='htmltestproduct',
			productVersion='3.1',
			packageVersion='1',
			name='Product HTML Test',
			licenseRequired=False,
			setupScript='setup.ins',
			uninstallScript='uninstall.ins',
			updateScript='update.ins',
			alwaysScript='always.ins',
			onceScript='once.ins',
			priority=0,
			description="asdf",
			advice="lolnope",
			changelog=None,
			windowsSoftwareIds=None
		)
	])

	expected = u'[\n    {\n        "onceScript": "once.ins", \n        "windowsSoftwareIds": null, \n        "description": "asdf", \n        "advice": "lolnope", \n        "alwaysScript": "always.ins", \n        "updateScript": "update.ins", \n        "productClassIds": null, \n        "id": "htmltestproduct", \n        "licenseRequired": false, \n        "ident": "htmltestproduct;3.1;1", \n        "name": "Product HTML Test", \n        "changelog": null, \n        "customScript": null, \n        "uninstallScript": "uninstall.ins", \n        "userLoginScript": null, \n        "priority": 0, \n        "productVersion": "3.1", \n        "packageVersion": "1", \n        "type": "LocalbootProduct", \n        "setupScript": "setup.ins"\n    }\n]'

	assert expected == objectToBeautifiedText(obj)
def testSetProductPropertyHandlingBoolProductProperties(backendManager):
    product = LocalbootProduct('testproduct', '1.0', '2')
    backendManager.product_insertObject(product)

    testprop = BoolProductProperty(productId=product.id,
                                   productVersion=product.productVersion,
                                   packageVersion=product.packageVersion,
                                   propertyId=u"changeMe",
                                   defaultValues=[False])
    backendManager.productProperty_insertObject(testprop)

    client = OpsiClient('testclient.domain.invalid')
    backendManager.host_insertObject(client)

    backendManager.setProductProperty(product.id, testprop.propertyId, True,
                                      client.id)

    result = backendManager.productProperty_getObjects(
        propertyId=testprop.propertyId)
    assert len(result) == 1
    result = result[0]
    assert isinstance(result, BoolProductProperty)
    assert result.getPossibleValues() == [False, True]
    assert result.getDefaultValues() == [False]

    result = backendManager.productPropertyState_getObjects()
    assert len(result) == 1
    result = result[0]
    assert result.getObjectId() == client.id
    assert result.getValues() == [True]
Пример #12
0
def testObjectToBashOutput():
	product = LocalbootProduct(
		id='htmltestproduct',
		productVersion='3.1',
		packageVersion='1',
		name='Product HTML Test',
		licenseRequired=False,
		setupScript='setup.ins',
		uninstallScript='uninstall.ins',
		updateScript='update.ins',
		alwaysScript='always.ins',
		onceScript='once.ins',
		priority=0,
		description="asdf",
		advice="lolnope",
		changelog=None,
		windowsSoftwareIds=None
	)

	expected = {
		'RESULT': u'(\nRESULT1=${RESULT1[*]}\nRESULT2=${RESULT2[*]}\n)',
		'RESULT1': u'(\nonceScript="once.ins"\nwindowsSoftwareIds=""\ndescription="asdf"\nadvice="lolnope"\nalwaysScript="always.ins"\nupdateScript="update.ins"\nproductClassIds=""\nid="htmltestproduct"\nlicenseRequired="False"\nident="htmltestproduct;3.1;1"\nname="Product HTML Test"\nchangelog=""\ncustomScript=""\nuninstallScript="uninstall.ins"\nuserLoginScript=""\npriority="0"\nproductVersion="3.1"\npackageVersion="1"\ntype="LocalbootProduct"\nsetupScript="setup.ins"\n)',
		'RESULT2': u'(\nonceScript="once.ins"\nwindowsSoftwareIds=""\ndescription="asdf"\nadvice="lolnope"\nalwaysScript="always.ins"\nupdateScript="update.ins"\nproductClassIds=""\nid="htmltestproduct"\nlicenseRequired="False"\nident="htmltestproduct;3.1;1"\nname="Product HTML Test"\nchangelog=""\ncustomScript=""\nuninstallScript="uninstall.ins"\nuserLoginScript=""\npriority="0"\nproductVersion="3.1"\npackageVersion="1"\ntype="LocalbootProduct"\nsetupScript="setup.ins"\n)',
	}

	result = objectToBash([product, product])

	assert expected == result
	assert result['RESULT1'] == result['RESULT2']
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 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 createProducts(amount=2):
    for number in range(amount):
        yield LocalbootProduct(
            id='product{0}'.format(number),
            name=u'Product {0}'.format(number),
            productVersion='{0}'.format(number + 1),
            packageVersion='1',
            setupScript="setup.opsiscript",
            uninstallScript=u"uninstall.opsiscript",
            updateScript="update.opsiscript",
            description="This is product {0}".format(number),
            advice="Advice for product {0}".format(number),
        )
Пример #16
0
	def generateLocalbootProduct(self, index=0):
		return LocalbootProduct(
			id='product{0}'.format(index),
			productVersion=random.choice(self.productVersions),
			packageVersion=random.choice(self.packageVersions),
			name='Product {0}'.format(index),
			licenseRequired=random.choice(self.licenseRequirements),
			setupScript=random.choice(self.setupScripts),
			uninstallScript=random.choice(self.uninstallScripts),
			updateScript=random.choice(self.updateScripts),
			alwaysScript=random.choice(self.alwaysScripts),
			onceScript=random.choice(self.onceScripts),
			priority=random.choice(self.priorities),
			description=random.choice(self.descriptions),
			advice=random.choice(self.advices),
			changelog=None,
			windowsSoftwareIds=None
		)
def testSetProductPropertyFailingIfMultivalueIsFalse(backendManager):
    product = LocalbootProduct('testproduct', '1.0', '2')
    backendManager.product_insertObject(product)

    testprop = UnicodeProductProperty(productId=product.id,
                                      productVersion=product.productVersion,
                                      packageVersion=product.packageVersion,
                                      propertyId=u"rebootflag",
                                      possibleValues=["0", "1", "2", "3"],
                                      defaultValues=["0"],
                                      editable=False,
                                      multiValue=False)
    backendManager.productProperty_insertObject(testprop)

    client = OpsiClient('testclient.domain.invalid')
    backendManager.host_insertObject(client)

    with pytest.raises(ValueError):
        backendManager.setProductProperty(product.id, testprop.propertyId,
                                          ["1", "2"], client.id)
Пример #18
0
def testObjectToHtmlOutputIsAsExpected():
	product = LocalbootProduct(
		id='htmltestproduct',
		productVersion='3.1',
		packageVersion='1',
		name='Product HTML Test',
		licenseRequired=False,
		setupScript='setup.ins',
		uninstallScript='uninstall.ins',
		updateScript='update.ins',
		alwaysScript='always.ins',
		onceScript='once.ins',
		priority=0,
		description="asdf",
		advice="lolnope",
		changelog=None,
		windowsSoftwareIds=None
	)

	expected = u'{<div style="padding-left: 3em;"><font class="json_key">"onceScript"</font>: "once.ins",<br />\n<font class="json_key">"windowsSoftwareIds"</font>: null,<br />\n<font class="json_key">"description"</font>: "asdf",<br />\n<font class="json_key">"advice"</font>: "lolnope",<br />\n<font class="json_key">"alwaysScript"</font>: "always.ins",<br />\n<font class="json_key">"updateScript"</font>: "update.ins",<br />\n<font class="json_key">"productClassIds"</font>: null,<br />\n<font class="json_key">"id"</font>: "htmltestproduct",<br />\n<font class="json_key">"licenseRequired"</font>: false,<br />\n<font class="json_key">"ident"</font>: "htmltestproduct;3.1;1",<br />\n<font class="json_key">"name"</font>: "Product&nbsp;HTML&nbsp;Test",<br />\n<font class="json_key">"changelog"</font>: null,<br />\n<font class="json_key">"customScript"</font>: null,<br />\n<font class="json_key">"uninstallScript"</font>: "uninstall.ins",<br />\n<font class="json_key">"userLoginScript"</font>: null,<br />\n<font class="json_key">"priority"</font>: 0,<br />\n<font class="json_key">"productVersion"</font>: "3.1",<br />\n<font class="json_key">"packageVersion"</font>: "1",<br />\n<font class="json_key">"type"</font>: "LocalbootProduct",<br />\n<font class="json_key">"setupScript"</font>: "setup.ins"</div>}'
	assert expected == objectToHtml(product)
def testSetProductPropertyHandlingMissingObjects(backendManager, productExists,
                                                 propertyExists, clientExists):
    expectedProperties = 0
    productId = 'existence'

    if productExists:
        product = LocalbootProduct(productId, '1.0', '1')
        backendManager.product_insertObject(product)

        if propertyExists:
            testprop = UnicodeProductProperty(
                productId=product.id,
                productVersion=product.productVersion,
                packageVersion=product.packageVersion,
                propertyId=u"changer",
                possibleValues=["True", "False"],
                defaultValues=["False"],
                editable=True,
                multiValue=False)
            backendManager.productProperty_insertObject(testprop)

            expectedProperties += 1

    with pytest.raises(BackendMissingDataError):
        backendManager.setProductProperty(productId, 'nothere', False)

    assert len(
        backendManager.productProperty_getObjects()) == expectedProperties

    if clientExists:
        client = OpsiClient('testclient.domain.invalid')
        backendManager.host_insertObject(client)

    with pytest.raises(BackendMissingDataError):
        backendManager.setProductProperty(productId, 'nothere', False,
                                          'testclient.domain.invalid')

    assert len(
        backendManager.productProperty_getObjects()) == expectedProperties
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)
Пример #21
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
def testSetProductPropertiesWithMultipleValues(backendManager):
    product = LocalbootProduct('testproduct', '1.0', '2')
    backendManager.product_insertObject(product)

    testprop = UnicodeProductProperty(productId=product.id,
                                      productVersion=product.productVersion,
                                      packageVersion=product.packageVersion,
                                      propertyId=u"rebootflag",
                                      possibleValues=["0", "1", "2", "3"],
                                      defaultValues=["0"],
                                      editable=False,
                                      multiValue=True)
    donotchange = UnicodeProductProperty(
        productId=product.id,
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        propertyId=u"upgradeproducts",
        possibleValues=["firefox", "opsi-vhd-control", "winscp"],
        defaultValues=["firefox", "opsi-vhd-control", "winscp"],
        editable=True,
        multiValue=True)

    backendManager.productProperty_insertObject(testprop)
    backendManager.productProperty_insertObject(donotchange)

    client = OpsiClient('testclient.domain.invalid')
    backendManager.host_insertObject(client)

    depotIds = set()
    for depot in getDepotServers():
        depotIds.add(depot.id)
        backendManager.host_insertObject(depot)

    for depotId in depotIds:
        backendManager.setProductProperties(product.id,
                                            {testprop.propertyId: ["1", "2"]},
                                            depotId)

    result = backendManager.productProperty_getObjects(
        propertyId=donotchange.propertyId)
    assert len(result) == 1
    result = result[0]
    assert isinstance(result, UnicodeProductProperty)
    assert result.getPossibleValues() == [
        "firefox", "opsi-vhd-control", "winscp"
    ]
    assert result.getDefaultValues() == [
        "firefox", "opsi-vhd-control", "winscp"
    ]

    result = backendManager.productProperty_getObjects(
        propertyId=testprop.propertyId)
    assert len(result) == 1
    result = result[0]
    assert isinstance(result, UnicodeProductProperty)
    assert result.getPossibleValues() == ["0", "1", "2", "3"]
    assert result.getDefaultValues() == ["0"]

    results = backendManager.productPropertyState_getObjects()
    assert len(results) == len(depotIds)

    for result in results:
        assert result.getObjectId() in depotIds
        print("Checking {0!r}".format(result))

        if result.propertyId == donotchange.propertyId:
            assert result.getValues() == donotchange.getPossibleValues()
        elif result.propertyId == testprop.propertyId:
            assert result.getValues() == ["1", "2"]
        else:
            raise ValueError("Unexpected property state: {0!r}".format(result))
def testSetProductPropertyNotConcatenatingStrings(backendManager):
    product = LocalbootProduct('testproduct', '1.0', '2')
    backendManager.product_insertObject(product)

    testprop = UnicodeProductProperty(productId=product.id,
                                      productVersion=product.productVersion,
                                      packageVersion=product.packageVersion,
                                      propertyId=u"rebootflag",
                                      possibleValues=["0", "1", "2", "3"],
                                      defaultValues=["0"],
                                      editable=False,
                                      multiValue=False)
    donotchange = UnicodeProductProperty(
        productId=product.id,
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        propertyId=u"upgradeproducts",
        possibleValues=["firefox", "opsi-vhd-control", "winscp"],
        defaultValues=["firefox", "opsi-vhd-control", "winscp"],
        editable=True,
        multiValue=True)

    backendManager.productProperty_insertObject(testprop)
    backendManager.productProperty_insertObject(donotchange)

    client = OpsiClient('testclient.domain.invalid')
    backendManager.host_insertObject(client)

    sideeffectPropState = ProductPropertyState(
        productId=product.id,
        propertyId=donotchange.propertyId,
        objectId=client.id,
        values=donotchange.getDefaultValues())
    backendManager.productPropertyState_insertObject(sideeffectPropState)

    backendManager.setProductProperty(product.id, testprop.propertyId, "1",
                                      client.id)

    result = backendManager.productProperty_getObjects(
        propertyId=donotchange.propertyId)
    assert len(result) == 1
    result = result[0]
    assert isinstance(result, UnicodeProductProperty)
    assert result.getPossibleValues() == [
        "firefox", "opsi-vhd-control", "winscp"
    ]
    assert result.getDefaultValues() == [
        "firefox", "opsi-vhd-control", "winscp"
    ]

    result = backendManager.productProperty_getObjects(
        propertyId=testprop.propertyId)
    assert len(result) == 1
    result = result[0]
    assert isinstance(result, UnicodeProductProperty)
    assert result.getPossibleValues() == ["0", "1", "2", "3"]
    assert result.getDefaultValues() == ["0"]

    results = backendManager.productPropertyState_getObjects()
    assert len(results) == 2

    for result in results:
        assert result.getObjectId() == client.id
        print("Checking {0!r}".format(result))

        if result.propertyId == donotchange.propertyId:
            assert result.getValues() == donotchange.getPossibleValues()
        elif result.propertyId == testprop.propertyId:
            assert result.getValues() == ["1"]
        else:
            raise ValueError("Unexpected property state: {0!r}".format(result))
Пример #24
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
def testSetProductPropertyWithoutSideEffects(backendManager, createDepotState):
    product = LocalbootProduct('aboabo', '1.0', '2')
    backendManager.product_insertObject(product)

    testprop = UnicodeProductProperty(productId=product.id,
                                      productVersion=product.productVersion,
                                      packageVersion=product.packageVersion,
                                      propertyId=u"changeMe",
                                      possibleValues=["True", "NO NO NO"],
                                      defaultValues=["NOT YOUR IMAGE"],
                                      editable=True,
                                      multiValue=False)
    untouchable = UnicodeProductProperty(
        productId=product.id,
        productVersion=product.productVersion,
        packageVersion=product.packageVersion,
        propertyId=u"ucanttouchthis",
        possibleValues=["Chocolate", "Starfish"],
        defaultValues=["Chocolate"],
        editable=True,
        multiValue=False)
    backendManager.productProperty_insertObject(testprop)
    backendManager.productProperty_insertObject(untouchable)

    configserver = getConfigServer()
    depot = OpsiDepotserver('biscuit.some.test')
    backendManager.host_insertObject(configserver)
    backendManager.host_insertObject(depot)

    expectedStates = 0
    if createDepotState:
        depotProdState = ProductPropertyState(
            productId=product.id,
            propertyId=testprop.propertyId,
            objectId=depot.id,
            values=testprop.getDefaultValues())
        backendManager.productPropertyState_insertObject(depotProdState)
        expectedStates += 1

    backendManager.setProductProperty(product.id, testprop.propertyId,
                                      'Starfish')

    results = backendManager.productProperty_getObjects()
    assert len(results) == 2

    for result in results:
        print("Checking {0!r}".format(result))
        assert isinstance(result, UnicodeProductProperty)

        if result.propertyId == untouchable.propertyId:
            assert result.getDefaultValues() == untouchable.getDefaultValues()
            assert result.getPossibleValues() == untouchable.getPossibleValues(
            )
        elif result.propertyId == testprop.propertyId:
            assert result.getDefaultValues() == testprop.getDefaultValues()
            assert result.getPossibleValues() == testprop.getPossibleValues()
        else:
            raise ValueError("Unexpected property: {0!r}".format(result))

    states = backendManager.productPropertyState_getObjects()
    assert len(states) == expectedStates

    if createDepotState:
        pps = states.pop()
        assert pps.productId == product.id
        assert pps.propertyId == testprop.propertyId
        assert pps.objectId == depot.id
        assert pps.values == ['Starfish']
Пример #26
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
Пример #27
0
def getAvailableProducts():
    opsiAgent = LocalbootProduct(
        id='opsi-agent',
        name=u'opsi client agent',
        productVersion='4.0',
        packageVersion='1',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=95,
    )

    ultravnc = LocalbootProduct(
        id='ultravnc',
        name=u'Ult@VNC',
        productVersion='1.0.8.2',
        packageVersion='1',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=0,
    )

    firefox = LocalbootProduct(
        id='firefox',
        name=u'Mozilla Firefox',
        productVersion='3.6',
        packageVersion='1',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        updateScript="update.ins",
        priority=0,
    )

    flashplayer = LocalbootProduct(
        id='flashplayer',
        name=u'Adobe Flashplayer',
        productVersion='10.0.45.2',
        packageVersion='2',
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=0,
    )

    sysessential = LocalbootProduct(
        id='sysessential',
        name=u'Sys Essential',
        productVersion='1.10.0',
        packageVersion=2,
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=55,
    )

    javavm = LocalbootProduct(
        id='javavm',
        name=u'Sun Java',
        productVersion='1.6.20',
        packageVersion=2,
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=0,
    )

    jedit = LocalbootProduct(
        id='jedit',
        name=u'jEdit',
        productVersion='5.1.0',
        packageVersion=2,
        licenseRequired=False,
        setupScript="setup.ins",
        uninstallScript=u"uninstall.ins",
        priority=0,
    )

    products = [
        opsiAgent, ultravnc, flashplayer, javavm, jedit, firefox, sysessential
    ]

    return products
Пример #28
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']
Пример #29
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
Пример #30
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