Ejemplo 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
Ejemplo 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
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)
Ejemplo n.º 4
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