This script takes a local Maven repository and deploys it to a Nexus
staging repository as defined by the staging-profile-id.
"""
- status = subprocess.call(['deploy', 'nexus-stage', nexus_url, staging_profile_id, deploy_dir])
- sys.exit(status)
+ deploy_sys.deploy_nexus_stage(nexus_url,
+ staging_profile_id,
+ deploy_dir)
@click.command(name='nexus-stage-repo-close')
pool.join()
os.chdir(previous_dir)
+
+
+def deploy_nexus_stage(nexus_url, staging_profile_id, deploy_dir):
+ """Deploy Maven artifacts to Nexus staging repo.
+
+ Parameters:
+ nexus_url: URL to Nexus server. (Ex: https://nexus.example.org)
+ staging_profile_id: The staging profile id as defined in Nexus for the
+ staging repo.
+ deploy_dir: The directory to deploy. (Ex: /tmp/m2repo)
+
+ Sample:
+ lftools deploy nexus-stage http://192.168.1.26:8081/nexus 4e6f95cd2344 /tmp/slask
+ Deploying Maven artifacts to staging repo...
+ Staging repository aaf-1005 created.
+ /tmp/slask ~/LF/work/lftools-dev/lftools/shell
+ Uploading fstab
+ Uploading passwd
+ ~/LF/work/lftools-dev/lftools/shell
+ Completed uploading files to aaf-1005.
+ """
+ staging_repo_id = nexus_stage_repo_create(nexus_url, staging_profile_id)
+ log.info("Staging repository {} created.".format(staging_repo_id))
+
+ deploy_nexus_url = '{0}/service/local/staging/deployByRepositoryId/{1}'.format(
+ _format_url(nexus_url),
+ staging_repo_id)
+
+ log.debug("Nexus URL = {}".format(_format_url(deploy_nexus_url)))
+ deploy_nexus(deploy_nexus_url, deploy_dir)
+
+ nexus_stage_repo_close(nexus_url, staging_profile_id, staging_repo_id)
+ log.info("Completed uploading files to {}".format(staging_repo_id))
responses.add(responses.POST, success_upload_url,
status=201)
deploy_sys.deploy_nexus(nexus_url, deploy_dir)
+
+
+@pytest.mark.datafiles(
+ os.path.join(FIXTURE_DIR, 'deploy'),
+ )
+def test_nexus_deploy_stage(datafiles, responses):
+ """Test nexus_deploy_stage."""
+ url='http://valid.deploy.stage'
+ url_repo = 'service/local/staging/profiles'
+ staging_profile_id='93fb68073c18'
+ repo_id='test1-1030'
+
+ #Setup for nexus_stage_repo_create
+ xml_created = "<stagedRepositoryId>{}</stagedRepositoryId>".format(repo_id)
+ responses.add(responses.POST, '{}/{}/{}/start'.format(url, url_repo, staging_profile_id),
+ body=xml_created, status=201)
+
+ #Setup for deploy_nexus with no snapshot
+ os.chdir(str(datafiles))
+ nexus_deploy_url = '{}/service/local/staging/deployByRepositoryId/{}'.format(url, repo_id)
+ deploy_dir = 'm2repo'
+ test_files = ['4.0.3-SNAPSHOT/odlparent-lite-4.0.3-20181120.113136-1.pom',
+ '4.0.3-SNAPSHOT/odlparent-lite-4.0.3-20181120.113136-1.pom.sha1',
+ '4.0.3-SNAPSHOT/odlparent-lite-4.0.3-20181120.113136-1.pom.md5']
+ for file in test_files:
+ success_upload_url = '{}/{}'.format(nexus_deploy_url, file)
+ responses.add(responses.POST, success_upload_url,
+ status=201)
+
+ #Setup for nexus_stage_repo_close
+ responses.add(responses.POST, '{}/{}/{}/finish'.format(url, url_repo, staging_profile_id),
+ body=None, status=201)
+
+ #Execute test, should not return anything for successful run.
+ deploy_sys.deploy_nexus_stage (url, staging_profile_id, deploy_dir)