{"action":"created","comment":{"url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/comments/33276191","id":33276191,"diff_hunk":"@@ -1465,3 +1469,178 @@ def setenforce(mode):\n         ))\n \n     run('setenforce {0}'.format(mode))\n+\n+\n+def get_hostname_from_ip(ip):\n+    \"\"\"Retrives the hostname by logging into remote machine by IP.\n+    Specially for the systems who doesnt support reverse DNS.\n+    e.g usersys machines.\n+\n+    :param str ip: Remote host's IP address to retrive hostname.\n+    \"\"\"\n+    gethost = lambda: run('hostname')\n+    result = execute(gethost, host=ip)\n+    print('host', result[ip])\n+    return result[ip]\n+\n+\n+def create_openstack_instance(\n+        instance_name=None, image_name=None, flavor_name=None, ssh_key=None):\n+    \"\"\"Creates openstack Instance from Image and Assigns a floating IP \\\n+    to instance.\n+\n+    :param str instance_name: Openstack Instance name to create.\n+    :param str image_name: Openstack image name from which \\\n+    instance to be created.\n+    :param str flavor_name: Openstack flavor_name for instance. e.g m1.small.\n+    :param str ssh_key: ssh_key 'name' that you want to add to this instance.\n+\n+    ssh_key should be added to openstack project before running automation.\n+    Else the automation will fail.\n+    \"\"\"\n+    if (instance_name or image_name or flavor_name or ssh_key) is None:\n+        raise ValueError(\n+            'instance_name/image_name/flavor_name/ssh_key cannot be None.')\n+    network_name = 'satellite-jenkins'\n+    clientObj = client.Client(\n+        username='satellite-jenkins',\n+        api_key='dog8code',\n+        auth_url='http://qeos.lab.eng.rdu2.redhat.com:5000/v2.0',\n+        project_id='satellite-jenkins'\n+    )\n+    # Validate openstack credentials.\n+    clientObj.authenticate()\n+    # Validate ssh_key is added into openstack project\n+    clientObj.keypairs.find(name=ssh_key)\n+    image = clientObj.images.find(name=image_name)\n+    flavor = clientObj.flavors.find(name=flavor_name)\n+    network = clientObj.networks.find(label=network_name)\n+    floating_ip = clientObj.floating_ips.create(\n+        clientObj.floating_ip_pools.list()[0].name\n+    )\n+    # Create instance from the given parameters\n+    instance = clientObj.servers.create(\n+        name=instance_name,\n+        image=image.id,\n+        flavor=flavor.id,\n+        key_name=ssh_key,\n+        network=network.id\n+    )\n+    # Average time considered to wait for instance to get in \\\n+    # ACTIVE running state, for assigning floating ip\n+    time.sleep(300)\n+    instance.add_floating_ip(floating_ip)\n+    # Wait till DNS resolves the IP\n+    time.sleep(600)\n+    # Getting Hostname from IP\n+    env['INSTANCE_HOST'] = get_hostname_from_ip(str(floating_ip.ip))\n+\n+\n+def delete_openstack_instance(instance_name=None):\n+    \"\"\"Deletes openstack Instance.\n+\n+    :param str instance_name: Openstack instance name to delete.\n+    \"\"\"\n+    if instance_name is None:\n+        raise ValueError('Instance name cannot be None.')\n+    clientObj = client.Client(\n+        username='satellite-jenkins',\n+        api_key='dog8code',\n+        auth_url='http://qeos.lab.eng.rdu2.redhat.com:5000/v2.0',\n+        project_id='satellite-jenkins'\n+    )\n+    try:\n+        instance = clientObj.servers.find(name=instance_name)\n+    except novaclient.exceptions.NotFound:\n+        print('Instance {0} in not listed in Openstack project.'.format(\n+            instance_name\n+        ))\n+        return\n+    instance.delete()\n+\n+\n+def satellite_upgrade(admin_password=None):\n+    \"\"\"Upgrades satellite from already created Openstack image \\\n+    of old Satellite version to latest Satellite version compose.\n+\n+    The following environment variables affect this command:\n+\n+    ADMIN_PASSWORD\n+        Optional, defaults to 'changeme'. Foreman admin password.\n+    BASE_URL\n+        URL for the compose repository.\n+    \"\"\"\n+    base_url = os.environ.get('BASE_URL')\n+    if base_url is None:\n+        print('The BASE_URL environment variable should be defined')\n+        sys.exit(1)\n+    if admin_password is None:\n+        admin_password = os.environ.get('ADMIN_PASSWORD', 'changeme')\n+    # Removing rhel-released and rhel-optional repo\n+    run('rm -rf /etc/yum.repos.d/rhel-optional.repo')\n+    run('rm -rf /etc/yum.repos.d/rhel-released.repo')\n+    # Update the packages\n+    update_packages(quiet=True, warn_only=True)","path":"automation_tools/__init__.py","position":133,"original_position":133,"commit_id":"6014267a91bc6337ad8179c9ad2aa7f895c139f6","original_commit_id":"6014267a91bc6337ad8179c9ad2aa7f895c139f6","user":{"login":"elyezer","id":48132,"avatar_url":"https://avatars.githubusercontent.com/u/48132?v=3","gravatar_id":"","url":"https://api.github.com/users/elyezer","html_url":"https://github.com/elyezer","followers_url":"https://api.github.com/users/elyezer/followers","following_url":"https://api.github.com/users/elyezer/following{/other_user}","gists_url":"https://api.github.com/users/elyezer/gists{/gist_id}","starred_url":"https://api.github.com/users/elyezer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elyezer/subscriptions","organizations_url":"https://api.github.com/users/elyezer/orgs","repos_url":"https://api.github.com/users/elyezer/repos","events_url":"https://api.github.com/users/elyezer/events{/privacy}","received_events_url":"https://api.github.com/users/elyezer/received_events","type":"User","site_admin":false},"body":"If quiet is True than fabric will make warn_only True too. With that said just quiet=True is enough here.","created_at":"2015-06-25T16:42:26Z","updated_at":"2015-06-25T16:42:26Z","html_url":"https://github.com/SatelliteQE/automation-tools/pull/196#discussion_r33276191","pull_request_url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196","_links":{"self":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/comments/33276191"},"html":{"href":"https://github.com/SatelliteQE/automation-tools/pull/196#discussion_r33276191"},"pull_request":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196"}}},"pull_request":{"url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196","id":38557161,"html_url":"https://github.com/SatelliteQE/automation-tools/pull/196","diff_url":"https://github.com/SatelliteQE/automation-tools/pull/196.diff","patch_url":"https://github.com/SatelliteQE/automation-tools/pull/196.patch","issue_url":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/196","number":196,"state":"open","locked":false,"title":"[DO NOT MERGE] Satellite Upgrade Automation","user":{"login":"jyejare","id":11752425,"avatar_url":"https://avatars.githubusercontent.com/u/11752425?v=3","gravatar_id":"","url":"https://api.github.com/users/jyejare","html_url":"https://github.com/jyejare","followers_url":"https://api.github.com/users/jyejare/followers","following_url":"https://api.github.com/users/jyejare/following{/other_user}","gists_url":"https://api.github.com/users/jyejare/gists{/gist_id}","starred_url":"https://api.github.com/users/jyejare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyejare/subscriptions","organizations_url":"https://api.github.com/users/jyejare/orgs","repos_url":"https://api.github.com/users/jyejare/repos","events_url":"https://api.github.com/users/jyejare/events{/privacy}","received_events_url":"https://api.github.com/users/jyejare/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nI am very Happy to add this to automation tools as its going to reduce/save lot of manual efforts put on upgrade testing also this is my first major feature PR.\r\n\r\nSo the upgrade has been implemented by using Openstack images that we have created already.\r\nSo the the total time required for upgrade process is reduced, instead doing everything from scratch.\r\n\r\nProcedure is something like this:\r\n```\r\n- Pre-requisite:\r\n1. Get ready an image in openstack with old satellite version. e.g Sat 6.0.8\r\n2. Add public ssh key of execution machine to openstack manually well before running automation.\r\n- Steps Automated:\r\n3. Create an instance from openstack image.\r\n4. Get an hostname from instance IP to login into instance for upgrade process.\r\n5. Run upgrade commands on the step(3) instance.\r\n- Optional:\r\n6. Delete the instance after everything is done. (Automated)\r\n```\r\nFor playing with openstack, I have used novaclient python API. So for running the whole upgrade automation, it is very much required to install novaclient python package. So the same has been added into requirements.txt.\r\nFor more info on novaclient API, visit http://docs.openstack.org/developer/python-novaclient/api.html.\r\n\r\nAlso, please note that before installing novaclient python package, it is required to have python-devel package installed in execution system. Otherwise novaclient package installation fails.\r\nYou can install python-devel package by simply,\r\n```\r\nyum -y install python-devel\r\n```\r\n\r\nQ&A:\r\nHow to run upgrade automation ?\r\nAnswer : You can run upgrade automation using fab framework, as following command,\r\n```\r\n#BASE_URL=http://example.com/Satellite/x86_64/os/ \\\r\nfab -i <local private_key> product_upgrade:<product_name e.g 'satellite'>, <instance_name>,<image_name>,<instance_flavor>, <ssh_key>\r\n```\r\nAll the parameters and 'BASE_URL' environment variable to fab command are mandatory, else the upgrade will fail.","created_at":"2015-06-25T15:03:03Z","updated_at":"2015-06-25T16:42:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"05a584d64254dae585ae189bd72e33c25e586068","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196/commits","review_comments_url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196/comments","review_comment_url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/196/comments","statuses_url":"https://api.github.com/repos/SatelliteQE/automation-tools/statuses/6014267a91bc6337ad8179c9ad2aa7f895c139f6","head":{"label":"jyejare:issue_193","ref":"issue_193","sha":"6014267a91bc6337ad8179c9ad2aa7f895c139f6","user":{"login":"jyejare","id":11752425,"avatar_url":"https://avatars.githubusercontent.com/u/11752425?v=3","gravatar_id":"","url":"https://api.github.com/users/jyejare","html_url":"https://github.com/jyejare","followers_url":"https://api.github.com/users/jyejare/followers","following_url":"https://api.github.com/users/jyejare/following{/other_user}","gists_url":"https://api.github.com/users/jyejare/gists{/gist_id}","starred_url":"https://api.github.com/users/jyejare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyejare/subscriptions","organizations_url":"https://api.github.com/users/jyejare/orgs","repos_url":"https://api.github.com/users/jyejare/repos","events_url":"https://api.github.com/users/jyejare/events{/privacy}","received_events_url":"https://api.github.com/users/jyejare/received_events","type":"User","site_admin":false},"repo":{"id":37851466,"name":"automation-tools","full_name":"jyejare/automation-tools","owner":{"login":"jyejare","id":11752425,"avatar_url":"https://avatars.githubusercontent.com/u/11752425?v=3","gravatar_id":"","url":"https://api.github.com/users/jyejare","html_url":"https://github.com/jyejare","followers_url":"https://api.github.com/users/jyejare/followers","following_url":"https://api.github.com/users/jyejare/following{/other_user}","gists_url":"https://api.github.com/users/jyejare/gists{/gist_id}","starred_url":"https://api.github.com/users/jyejare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyejare/subscriptions","organizations_url":"https://api.github.com/users/jyejare/orgs","repos_url":"https://api.github.com/users/jyejare/repos","events_url":"https://api.github.com/users/jyejare/events{/privacy}","received_events_url":"https://api.github.com/users/jyejare/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jyejare/automation-tools","description":"A set of tools to help automating testing Foreman with Robottelo (https://github.com/SatelliteQE/robottelo)","fork":true,"url":"https://api.github.com/repos/jyejare/automation-tools","forks_url":"https://api.github.com/repos/jyejare/automation-tools/forks","keys_url":"https://api.github.com/repos/jyejare/automation-tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jyejare/automation-tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jyejare/automation-tools/teams","hooks_url":"https://api.github.com/repos/jyejare/automation-tools/hooks","issue_events_url":"https://api.github.com/repos/jyejare/automation-tools/issues/events{/number}","events_url":"https://api.github.com/repos/jyejare/automation-tools/events","assignees_url":"https://api.github.com/repos/jyejare/automation-tools/assignees{/user}","branches_url":"https://api.github.com/repos/jyejare/automation-tools/branches{/branch}","tags_url":"https://api.github.com/repos/jyejare/automation-tools/tags","blobs_url":"https://api.github.com/repos/jyejare/automation-tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jyejare/automation-tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jyejare/automation-tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/jyejare/automation-tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jyejare/automation-tools/statuses/{sha}","languages_url":"https://api.github.com/repos/jyejare/automation-tools/languages","stargazers_url":"https://api.github.com/repos/jyejare/automation-tools/stargazers","contributors_url":"https://api.github.com/repos/jyejare/automation-tools/contributors","subscribers_url":"https://api.github.com/repos/jyejare/automation-tools/subscribers","subscription_url":"https://api.github.com/repos/jyejare/automation-tools/subscription","commits_url":"https://api.github.com/repos/jyejare/automation-tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/jyejare/automation-tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/jyejare/automation-tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/jyejare/automation-tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/jyejare/automation-tools/contents/{+path}","compare_url":"https://api.github.com/repos/jyejare/automation-tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jyejare/automation-tools/merges","archive_url":"https://api.github.com/repos/jyejare/automation-tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jyejare/automation-tools/downloads","issues_url":"https://api.github.com/repos/jyejare/automation-tools/issues{/number}","pulls_url":"https://api.github.com/repos/jyejare/automation-tools/pulls{/number}","milestones_url":"https://api.github.com/repos/jyejare/automation-tools/milestones{/number}","notifications_url":"https://api.github.com/repos/jyejare/automation-tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jyejare/automation-tools/labels{/name}","releases_url":"https://api.github.com/repos/jyejare/automation-tools/releases{/id}","created_at":"2015-06-22T11:23:46Z","updated_at":"2015-06-22T11:23:47Z","pushed_at":"2015-06-25T15:12:06Z","git_url":"git://github.com/jyejare/automation-tools.git","ssh_url":"git@github.com:jyejare/automation-tools.git","clone_url":"https://github.com/jyejare/automation-tools.git","svn_url":"https://github.com/jyejare/automation-tools","homepage":"","size":1321,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SatelliteQE:master","ref":"master","sha":"8ba1b9dd9c3d37051be9c411c1daebe31078b4c5","user":{"login":"SatelliteQE","id":8754276,"avatar_url":"https://avatars.githubusercontent.com/u/8754276?v=3","gravatar_id":"","url":"https://api.github.com/users/SatelliteQE","html_url":"https://github.com/SatelliteQE","followers_url":"https://api.github.com/users/SatelliteQE/followers","following_url":"https://api.github.com/users/SatelliteQE/following{/other_user}","gists_url":"https://api.github.com/users/SatelliteQE/gists{/gist_id}","starred_url":"https://api.github.com/users/SatelliteQE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SatelliteQE/subscriptions","organizations_url":"https://api.github.com/users/SatelliteQE/orgs","repos_url":"https://api.github.com/users/SatelliteQE/repos","events_url":"https://api.github.com/users/SatelliteQE/events{/privacy}","received_events_url":"https://api.github.com/users/SatelliteQE/received_events","type":"Organization","site_admin":false},"repo":{"id":22513327,"name":"automation-tools","full_name":"SatelliteQE/automation-tools","owner":{"login":"SatelliteQE","id":8754276,"avatar_url":"https://avatars.githubusercontent.com/u/8754276?v=3","gravatar_id":"","url":"https://api.github.com/users/SatelliteQE","html_url":"https://github.com/SatelliteQE","followers_url":"https://api.github.com/users/SatelliteQE/followers","following_url":"https://api.github.com/users/SatelliteQE/following{/other_user}","gists_url":"https://api.github.com/users/SatelliteQE/gists{/gist_id}","starred_url":"https://api.github.com/users/SatelliteQE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SatelliteQE/subscriptions","organizations_url":"https://api.github.com/users/SatelliteQE/orgs","repos_url":"https://api.github.com/users/SatelliteQE/repos","events_url":"https://api.github.com/users/SatelliteQE/events{/privacy}","received_events_url":"https://api.github.com/users/SatelliteQE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SatelliteQE/automation-tools","description":"A set of tools to help automating testing Foreman with Robottelo (https://github.com/SatelliteQE/robottelo)","fork":false,"url":"https://api.github.com/repos/SatelliteQE/automation-tools","forks_url":"https://api.github.com/repos/SatelliteQE/automation-tools/forks","keys_url":"https://api.github.com/repos/SatelliteQE/automation-tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SatelliteQE/automation-tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SatelliteQE/automation-tools/teams","hooks_url":"https://api.github.com/repos/SatelliteQE/automation-tools/hooks","issue_events_url":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/events{/number}","events_url":"https://api.github.com/repos/SatelliteQE/automation-tools/events","assignees_url":"https://api.github.com/repos/SatelliteQE/automation-tools/assignees{/user}","branches_url":"https://api.github.com/repos/SatelliteQE/automation-tools/branches{/branch}","tags_url":"https://api.github.com/repos/SatelliteQE/automation-tools/tags","blobs_url":"https://api.github.com/repos/SatelliteQE/automation-tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SatelliteQE/automation-tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SatelliteQE/automation-tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/SatelliteQE/automation-tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SatelliteQE/automation-tools/statuses/{sha}","languages_url":"https://api.github.com/repos/SatelliteQE/automation-tools/languages","stargazers_url":"https://api.github.com/repos/SatelliteQE/automation-tools/stargazers","contributors_url":"https://api.github.com/repos/SatelliteQE/automation-tools/contributors","subscribers_url":"https://api.github.com/repos/SatelliteQE/automation-tools/subscribers","subscription_url":"https://api.github.com/repos/SatelliteQE/automation-tools/subscription","commits_url":"https://api.github.com/repos/SatelliteQE/automation-tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/SatelliteQE/automation-tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/SatelliteQE/automation-tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/SatelliteQE/automation-tools/contents/{+path}","compare_url":"https://api.github.com/repos/SatelliteQE/automation-tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SatelliteQE/automation-tools/merges","archive_url":"https://api.github.com/repos/SatelliteQE/automation-tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SatelliteQE/automation-tools/downloads","issues_url":"https://api.github.com/repos/SatelliteQE/automation-tools/issues{/number}","pulls_url":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls{/number}","milestones_url":"https://api.github.com/repos/SatelliteQE/automation-tools/milestones{/number}","notifications_url":"https://api.github.com/repos/SatelliteQE/automation-tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SatelliteQE/automation-tools/labels{/name}","releases_url":"https://api.github.com/repos/SatelliteQE/automation-tools/releases{/id}","created_at":"2014-08-01T14:27:34Z","updated_at":"2015-05-20T03:49:25Z","pushed_at":"2015-06-25T15:12:06Z","git_url":"git://github.com/SatelliteQE/automation-tools.git","ssh_url":"git@github.com:SatelliteQE/automation-tools.git","clone_url":"https://github.com/SatelliteQE/automation-tools.git","svn_url":"https://github.com/SatelliteQE/automation-tools","homepage":"","size":1306,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":16,"forks":11,"open_issues":16,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196"},"html":{"href":"https://github.com/SatelliteQE/automation-tools/pull/196"},"issue":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/196"},"comments":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/issues/196/comments"},"review_comments":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196/comments"},"review_comment":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/pulls/196/commits"},"statuses":{"href":"https://api.github.com/repos/SatelliteQE/automation-tools/statuses/6014267a91bc6337ad8179c9ad2aa7f895c139f6"}}}}