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)
Esempio n. 2
0
def createClientAndDepot(backend):
	client = OpsiClient(
		id='backend-test-1.vmnat.local',
		description='Unittest Test client.'
	)

	depot = OpsiDepotserver(
		id='depotserver1.some.test',
		description='Test Depot',
	)

	backend.host_createObjects([client, depot])

	clientConfigDepotId = UnicodeConfig(
		id=u'clientconfig.depot.id',
		description=u'Depotserver to use',
		possibleValues=[],
		defaultValues=[depot.id]
	)

	backend.config_createObjects(clientConfigDepotId)

	clientDepotMappingConfigState = ConfigState(
		configId=clientConfigDepotId.getId(),
		objectId=client.getId(),
		values=depot.getId()
	)

	backend.configState_createObjects(clientDepotMappingConfigState)

	return client, depot
Esempio n. 3
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']
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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