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
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 addServers(backend): localHostFqdn = getLocalHostFqdn() configServer = OpsiConfigserver( id=localHostFqdn, depotRemoteUrl='smb://192.168.123.1/opsi_depot') backend.host_createObjects([configServer]) _, domain = localHostFqdn.split('.', 1) def getDepotRemoteUrl(index): if index % 2 == 0: return 'smb://192.168.123.{}/opsi_depot'.format(index) else: return 'smb://somename/opsi_depot' depots = [ OpsiDepotserver(id='depot{n}.{domain}'.format(n=index, domain=domain), depotRemoteUrl=getDepotRemoteUrl(index)) for index in range(10) ] backend.host_createObjects(depots) clients = [ OpsiClient(id='client{n}.{domain}'.format(n=index, domain=domain)) for index in range(10) ] backend.host_createObjects(clients)
def getDepotServers(): depotserver1 = OpsiDepotserver( id='depotserver1.uib.local', opsiHostKey='19012334567845645678901232789012', depotLocalUrl='file:///var/lib/opsi/depot', depotRemoteUrl='smb://depotserver1.test.invalid/opsi_depot', depotWebdavUrl=u'webdavs://depotserver1.test.invalid:4447/depot', repositoryLocalUrl='file:///var/lib/opsi/repository', repositoryRemoteUrl= 'webdavs://depotserver1.test.invalid:4447/repository', workbenchLocalUrl='file:///var/lib/opsi/workbench', workbenchRemoteUrl=u'smb://depotserver1.test.invalid/opsi_workbench', description='A depot', notes='D€pot 1', hardwareAddress=None, ipAddress=None, inventoryNumber='00000000002', networkAddress='192.168.2.0/24', maxBandwidth=10000) depotserver2 = OpsiDepotserver( id='depotserver2.test.invalid', opsiHostKey='93aa22f38a678c64ef678a012d2e82f2', depotLocalUrl='file:///var/lib/opsi/depot', depotRemoteUrl='smb://depotserver2.test.invalid/opsi_depot', repositoryLocalUrl='file:///var/lib/opsi/repository', repositoryRemoteUrl= 'webdavs://depotserver2.test.invalid:4447/repository', workbenchLocalUrl='file:///var/lib/opsi/workbench', workbenchRemoteUrl=u'smb://depotserver2.test.invalid/opsi_workbench', description='Second depot', notes=None, # no notes here hardwareAddress='00:01:09:07:11:aa', ipAddress='192.168.10.1', inventoryNumber='', networkAddress='192.168.10.0/24', maxBandwidth=240000) return depotserver1, depotserver2
def testComparingConfigserverToDepotserverFails(configServerReference): depotserver = OpsiDepotserver( id='depotserver1.test.invalid', opsiHostKey='19012334567845645678901232789012', depotLocalUrl='file:///opt/pcbin/install', depotRemoteUrl='smb://depotserver1.test.invalid/opt_pcbin/install', repositoryLocalUrl='file:///var/lib/opsi/repository', repositoryRemoteUrl= 'webdavs://depotserver1.test.invalid:4447/repository', description='A depot', notes='D€pot 1', hardwareAddress=None, ipAddress=None, inventoryNumber='00000000002', networkAddress='192.168.2.0/24', maxBandwidth=10000) assert configServerReference != depotserver
def depot(): return OpsiDepotserver(id='depotserver1.test.invalid')
def anotherDepot(): return OpsiDepotserver(id='depotserver2.some.test')
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']
def testRenamingDepotServer(extendedConfigDataBackend, addressType, newId='hello.world.test'): backend = extendedConfigDataBackend configServer = getConfigServer() backend.host_createObjects(configServer) initializeConfigs(backend) # TODO: add test variant that uses the hostname or IP in the addresses # TODO: relevant for #3034? if addressType != 'fqdn': raise RuntimeError("Unsupported address type") address = 'toberenamed.domain.test' depots = list(getDepotServers()) oldServer = OpsiDepotserver( id='toberenamed.domain.test', depotLocalUrl='file:///var/lib/opsi/depot', depotRemoteUrl='smb://{address}/opsi_depot'.format(address=address), depotWebdavUrl=u'webdavs://{address}:4447/depot'.format(address=address), repositoryLocalUrl='file:///var/lib/opsi/repository', repositoryRemoteUrl='webdavs://{address}:4447/repository'.format(address=address), workbenchLocalUrl='file:///var/lib/opsi/workbench', workbenchRemoteUrl=u'smb://{address}/opsi_workbench'.format(address=address), ) depots.append(oldServer) backend.host_createObjects(depots) products = list(getLocalbootProducts()) + [getNetbootProduct()] backend.product_createObjects(products) originalProductsOnDepots = getProductsOnDepot(products, oldServer, depots) backend.productOnDepot_createObjects(originalProductsOnDepots) productsOnOldDepot = backend.productOnDepot_getObjects(depotId=oldServer.id) product1 = products[0] specialProperty = UnicodeProductProperty( productId=product1.id, productVersion=product1.productVersion, packageVersion=product1.packageVersion, propertyId="changeMe", possibleValues=['foo', oldServer.id, 'baz'], defaultValues=['foo', oldServer.id], editable=False, multiValue=True ) properties = [ UnicodeProductProperty( productId=product1.id, productVersion=product1.productVersion, packageVersion=product1.packageVersion, propertyId="overridden", possibleValues=['foo', 'bar', 'baz'], defaultValues=['foo'], editable=True, multiValue=True ), BoolProductProperty( productId=product1.id, productVersion=product1.productVersion, packageVersion=product1.packageVersion, propertyId="irrelevant2", defaultValues=True ), specialProperty, ] backend.productProperty_createObjects(properties) oldProperties = backend.productProperty_getObjects() specialProdPropertyState = ProductPropertyState( productId=product1.id, propertyId=properties[0].propertyId, objectId=oldServer.id, values=[oldServer.id] ) productPropertyStates = list(getProductPropertyStates(properties, depots, depots)) productPropertyStates.append(specialProdPropertyState) backend.productPropertyState_createObjects(productPropertyStates) oldProductPropertyStates = backend.productPropertyState_getObjects() testConfig = UnicodeConfig( id=u'test.config.rename', description=u'Testing value rename', possibleValues=['random value', oldServer.id, 'another value'], defaultValues=[oldServer.id], editable=True, multiValue=False ) configs = list(getConfigs()) configs.append(testConfig) configs.append( UnicodeConfig( id=u'clientconfig.depot.id', # get's special treatment description=u'ID of the opsi depot to use', possibleValues=[configServer.id, oldServer.id], defaultValues=[oldServer.id], editable=True, multiValue=False ) ) configs.append( UnicodeConfig( id=u'clientconfig.configserver.url', # get's special treatment description=u'URL(s) of opsi config service(s) to use', possibleValues=[u'https://%s:4447/rpc' % server for server in (configServer.id, oldServer.id)], defaultValues=[u'https://%s:4447/rpc' % configServer.id], editable=True, multiValue=True ) ) backend.config_createObjects(configs) oldConfigs = backend.config_getObjects() testConfigState = ConfigState( configId=testConfig.id, objectId=oldServer.id, values=["broken glass", oldServer.id, "red"] ) manyDepots = depots * 4 configStates = list(getConfigStates(configs, manyDepots[:7], [None, oldServer])) configStates.append(testConfigState) backend.configState_createObjects(configStates) oldConfigStates = backend.configState_getObjects() configStatesFromDifferentObjects = [cs for cs in oldConfigStates if not cs.objectId == oldServer.id] secondaryDepot = OpsiDepotserver( id='sub-{0}'.format(oldServer.id), isMasterDepot=False, masterDepotId=oldServer.id ) backend.host_createObjects(secondaryDepot) backend.host_renameOpsiDepotserver(oldServer.id, newId) assert not backend.host_getObjects(id=oldServer.id) newServer = backend.host_getObjects(id=newId)[0] assert newServer.id == newId assert newServer.getType() == "OpsiDepotserver" assert newServer.depotLocalUrl == 'file:///var/lib/opsi/depot' assert newServer.repositoryLocalUrl == 'file:///var/lib/opsi/repository' assert newServer.workbenchLocalUrl == 'file:///var/lib/opsi/workbench' assert newServer.depotRemoteUrl == u'smb://%s/opsi_depot' % newId assert newServer.depotWebdavUrl == u'webdavs://%s:4447/depot' % newId assert newServer.repositoryRemoteUrl == u'webdavs://%s:4447/repository' % newId assert newServer.workbenchRemoteUrl == u'smb://{}/opsi_workbench'.format(newId) assert not backend.productOnDepot_getObjects(depotId=oldServer.id) productsOnNewDepot = backend.productOnDepot_getObjects(depotId=newId) assert len(productsOnOldDepot) == len(productsOnNewDepot) newProperties = backend.productProperty_getObjects() assert len(newProperties) == len(oldProperties) specialPropertyChecked = False for productProperty in newProperties: if productProperty.propertyId == specialProperty.propertyId: assert oldServer.id not in productProperty.possibleValues assert newId in productProperty.possibleValues assert oldServer.id not in productProperty.defaultValues assert newId in productProperty.defaultValues specialPropertyChecked = True assert specialPropertyChecked, "Missing property {0}".format(specialProperty.propertyId) newProductPropertyStates = backend.productPropertyState_getObjects() assert len(oldProductPropertyStates) == len(newProductPropertyStates) assert not any(pps.objectId == oldServer.id for pps in newProductPropertyStates) assert not any(oldServer.id in pps.values for pps in newProductPropertyStates) newConfigs = backend.config_getObjects() assert len(oldConfigs) == len(newConfigs) configsTested = 0 for config in newConfigs: assert oldServer.id not in config.possibleValues assert oldServer.id not in config.defaultValues if config.id == testConfig.id: assert newId in config.possibleValues assert newId in config.defaultValues assert len(testConfig.possibleValues) == len(config.possibleValues) assert len(testConfig.defaultValues) == len(config.defaultValues) configsTested += 1 elif config.id == 'clientconfig.configserver.url': assert 1 == len(config.defaultValues) assert newId not in config.defaultValues[0] # Default is config server assert 2 == len(config.possibleValues) # TODO: this could be relevant for #1571 if addressType == 'fqdn': assert any(newId in value for value in config.possibleValues) else: raise RuntimeError("Missing check for address type {0!r}".format(addressType)) configsTested += 1 elif config.id == 'clientconfig.depot.id': assert newId in config.possibleValues assert oldServer.id not in config.possibleValues assert 2 == len(config.possibleValues) assert [newId] == config.defaultValues configsTested += 1 assert 3 == configsTested newConfigStates = backend.configState_getObjects() assert len(oldConfigStates) == len(newConfigStates) newConfigStatesFromDifferentObjects = [cs for cs in newConfigStates if not cs.objectId == newId] assert len(configStatesFromDifferentObjects) == len(newConfigStatesFromDifferentObjects) configStateTested = False for configState in newConfigStates: assert oldServer.id not in configState.values assert configState.objectId != oldServer.id if configState.configId == testConfigState.configId: assert configState.objectId == newId configStateTested = True assert configStateTested, "Reference to ID not changed" newSecondaryDepot = backend.host_getObjects(id=secondaryDepot.id)[0] assert newSecondaryDepot.isMasterDepot is False assert newSecondaryDepot.masterDepotId == newId
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']
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
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
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 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
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)