def test_node_import_new(self): """Test importing a new node""" test_importer = PackageImport() test_importer.process_node_info(TestServerBase.DATA1) assert Node.query.count() == 1 assert Package.query.count() == 1
def dataimport(): """Import json formated package information from a node. Store this information into a database for later querying """ # Safeguard if request.method == 'PUT' or request.method == 'POST': request_json = request.get_json() importer = PackageImport() importer.process_node_info(request_json) #TODO: return node object? return Response(status=200) else: raise InvalidAPIUsage('Invalid request method', status_code=400)
def test_get_outdated_packages(self): self.repositories = Repositories() # create the demo repo data = {} data['name'] = 'Repo1' data['label'] = 'main' data['uri'] = 'http://de.archive.ubuntu.com/ubuntu/dists/precise/main/binary-amd64/Packages.gz' data['provider'] = 'apt' repo_id = self.repositories.create_repository(data) repo = Repository.query.filter_by(id=repo_id).first() path = os.path.dirname(__file__) datafile = os.path.join(path, 'data/install_tiny.txt') data_install = self.process_data(datafile) test_importer = PackageImport() test_importer.process_node_info(data_install) data = {'75da5ca65e2160e994c33d1006046c2be954efe804a24d34628d0c4cac791ce4': { "package": "accountsservice", "filename": "http://us.archive.ubuntu.com/ubuntu/pool/main/a/accountsservice/accountsservice_0.6.21-6ubuntu5.1_amd64.deb", "description": "query and manipulate user account information", "version": "0.6.21-6ubuntu5.1", "architecture": "amd64", "sha256": "75da5ca65e2160e994c33d1006046c2be954efe804a24d34628d0c4cac791ce4" }, } self.repositories.provider = MockRepository(data) self.repositories.update_repository(repo) self.assertEqual(RepoHistory.query.count(), 1) packages = self.repositories.get_outdated_packages('ponyexpress', [repo]) self.assertIsNotNone(packages) #self.assertNotEqual(packages, []) self.assertIsInstance(packages[0].upstream_version, dict) self.assertEqual(len(packages[0].upstream_version), 2) self.assertEqual(packages[0].pkgversion, '0.6.15-2ubuntu9') self.assertEqual(packages[0].upstream_version['latest'], '0.6.21-6ubuntu5.1')
def test_node_import_2nodes(self): """Test importing a node which exists in the db""" test_importer = PackageImport() test_importer.process_node_info(TestServerBase.DATA1) assert Node.query.count() == 1 assert Package.query.count() == 1 node = Node.query.first() assert node.packages.count() == 1 # Reimport data to simulate subsequent updates test_importer.process_node_info(TestServerBase.DATA2) assert Node.query.count() == 2 assert Package.query.count() == 2 nodes = Node.query.all() assert len(nodes) == 2
def test_update_repository(self): """Test package list downloading""" self.repositories = Repositories() repo = Repository() repo.id = 1 repo.provider = 'apt' repo.name = 'Test' repo.uri = 'http://de.archive.ubuntu.com/ubuntu/dists/precise/main/binary-amd64/Packages.gz' repo.label = 'Test' path = os.path.dirname(__file__) datafile = os.path.join(path, 'data/install_tiny.txt') data_install = self.process_data(datafile) test_importer = PackageImport() test_importer.process_node_info(data_install) self.repositories.provider = MockRepository() self.repositories.update_repository(repo) self.assertEqual(RepoHistory.query.count(), 1)
def test_node_import_package_update2(self): """Test importing a node which exists in the db""" path = os.path.dirname(__file__) datafile = os.path.join(path, "data/install.txt") data_install = self.process_data(datafile) test_importer = PackageImport() test_importer.process_node_info(data_install) assert Node.query.count() == 1 assert Package.query.count() == len(data_install["packages"]) datafile = os.path.join(path, "data/upgrade.txt") data_update = self.process_data(datafile) test_importer.process_node_info(data_update) assert Node.query.count() == 1 # Not ideal, but the easiest way assert Package.query.count() == 559 # Must update this sha if you change install.txt and or upgrade.txt package = Package.query.filter_by( sha="26608ec5e9ec05894eaea23d7b00855b6f7680a58385e1f825836a097ac09e90" ).first() assert package.name == "grub-common" assert package.version == "1.99-21ubuntu3.14" # Must have two packages of grub-common packages = Package.query.filter_by(name="grub-common").all() assert len(packages) == 2 np = Node.query.filter(Node.packages.any(name="grub-common")).all() assert len(np) == 1 # run another upgrade datafile = os.path.join(path, "data/upgrade2.txt") data_update = self.process_data(datafile) test_importer.process_node_info(data_update) assert Node.query.count() == 1 print(PackageHistory.query.count()) assert Package.query.count() == 579
def test_node_import_package_update(self): """Test importing a node which exists in the db""" test_importer = PackageImport() test_importer.process_node_info(DATA_UPDATE1) # Reimport data to simulate subsequent updates test_importer.process_node_info(DATA_UPDATE1) assert Node.query.count() == 1 assert Package.query.count() == 1 test_importer.process_node_info(DATA_UPDATE2) nodes = Node.query.all() assert len(nodes) == 2 packages = Package.query.all() # There need to be two packages stored in the db assert len(packages) == 2 package = Package.query.filter_by(sha=DATA_UPDATE2["packages"][0]["sha256"]).first() assert package.name == "openstack-deploy" assert package.version == "2.0" node = Node.query.filter_by(name="node2").first() assert node.name == "node2" assert node.packages.count() == 1 assert node.packages[0].version == "2.0" node = Node.query.filter_by(name="node1").first() assert node.name == "node1" assert node.packages.count() == 1 assert node.packages[0].version == "1.0"
def addNode(self, node_dict): """A method to add nodes for test purposes""" test_import = PackageImport() test_import.process_node_info(node_dict)