{"action":"created","comment":{"url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/comments/41600735","id":41600735,"diff_hunk":"@@ -1,7 +1,117 @@\n '''Common test methods'''\n \n+import os\n+import re\n+\n from behave import *\n \n+\n+def exec_service_cmd(context, action, service_name, host=None):\n+    if host == None:\n+        host = context.target_host\n+\n+    #cmd = context.service_cmd\n+    cmd = \"systemctl ACTION SERVICE_NAME\"\n+    cmd = re.sub(\"ACTION\", action, cmd)\n+    cmd = re.sub(\"SERVICE_NAME\", service_name, cmd)\n+\n+    result = context.remote_cmd(cmd='command',\n+                                host=host,\n+                                module_args=cmd,\n+                                ignore_rc=True)\n+\n+    if action == \"status\":\n+        emsg = \"Can not get the status of service %s\" % service_name\n+    else:\n+        emsg = \"Can not %s service %s\" % (action, service_name)\n+\n+    assert result, emsg\n+\n+    return result[0]['stdout']\n+\n+\n+@given(u'get the services from configure file')\n+def step_impl(context):\n+    svcs_all = {}\n+    for item in context.test_cfg.items('service_check'):\n+        svcs_all[item[0]] = item[1].split()\n+    context.svcs_all = svcs_all\n+\n+\n+@then(u'update services original status')\n+def step_impl(context):\n+    status_data = {}\n+    svcs_disabled = {}\n+    svcs_running = {}\n+    svcs_not_exist = {}\n+    load_pattern = \"Loaded:.*(disable|enable)\"\n+    active_pattern = \"Active:.*(running)\"\n+\n+    for host in context.svcs_all:\n+        svcs_disabled[host] = []\n+        svcs_running[host] = []\n+        for svc in context.svcs_all[host]:\n+            status = exec_service_cmd(context, 'status', svc, host)\n+\n+            loaded = re.findall(load_pattern, status)\n+            if not loaded:\n+                if host not in svcs_not_exist:\n+                    svcs_not_exist[host] = []\n+                svcs_not_exist[host].append(svc)\n+                context.svcs_all[host].remove(svc)\n+                continue\n+            if loaded == \"disabled\":\n+                svcs_disabled[host].append(svc)\n+\n+            running = re.findall(active_pattern, status)\n+            if running:\n+                svcs_running[host].append(svc)\n+\n+    context.svcs_running = svcs_running\n+    context.svcs_disabled = svcs_disabled\n+\n+    emsg = \"\"\n+    for host in svcs_not_exist:\n+        emsg += \"For host %s, service \" % host\n+        emsg += \"'%s' is not exist\" % \" \".join(svcs_not_exist[host])\n+    assert not svcs_not_exist, emsg\n+\n+\n+@given(u'\"{action}\" \"{status}\" services')\n+@then(u'\"{action}\" \"{status}\" services')\n+def step_impl(context, action, status):\n+    svcs = getattr(context, \"svcs_%s\" % status, None)\n+    assert svcs, \"Can not find %s service from context\" % status\n+\n+    for host in svcs:\n+        for svc in svcs[host]:\n+            exec_service_cmd(context, action, svc, host)\n+\n+\n+@when(u'services status is \"{status}\"')\n+@then(u'services status is \"{status}\"')\n+def step_impl(context, status):\n+    if status in ['running', 'dead', 'active', 'inactive']:\n+        pattern = r\"Active:.*?(%s)\" % status\n+        msg_pattern = r\"Active:.*\"\n+    else:\n+        pattern = r\"Loaded:.*?(%s)\" % status\n+        msg_pattern = r\"Loaded:.*\"\n+\n+    svcs = context.svcs_all\n+\n+    emsg = \"\"\n+    for host in svcs:\n+        for svc in svcs[host]:\n+            current_status = exec_service_cmd(context, \"status\", svc, host)\n+            if not re.findall(pattern, current_status):\n+                msg = re.findall(msg_pattern, current_status)[0]\n+\t\temsg += \"Service %s in host %s\" % (svc, host)\n+                emsg += \" is not %s but '%s'\" % (status, msg)\n+\n+    assert not emsg, emsg","path":"steps/common.py","position":112,"original_position":112,"commit_id":"fb8b1b6e5616fbd5464b4efe7679786dfd4cd5d2","original_commit_id":"fb8b1b6e5616fbd5464b4efe7679786dfd4cd5d2","user":{"login":"ypu","id":1137786,"avatar_url":"https://avatars.githubusercontent.com/u/1137786?v=3","gravatar_id":"","url":"https://api.github.com/users/ypu","html_url":"https://github.com/ypu","followers_url":"https://api.github.com/users/ypu/followers","following_url":"https://api.github.com/users/ypu/following{/other_user}","gists_url":"https://api.github.com/users/ypu/gists{/gist_id}","starred_url":"https://api.github.com/users/ypu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ypu/subscriptions","organizations_url":"https://api.github.com/users/ypu/orgs","repos_url":"https://api.github.com/users/ypu/repos","events_url":"https://api.github.com/users/ypu/events{/privacy}","received_events_url":"https://api.github.com/users/ypu/received_events","type":"User","site_admin":false},"body":"emsg is just the error message I want to print if this step failed. And if everything goes well, it should be empty. So the expect result is \"not emsg\" and the message assert should print is \"emsg\". It is like some kind of string flags in the test.","created_at":"2015-10-09T06:25:15Z","updated_at":"2015-10-09T06:25:15Z","html_url":"https://github.com/aweiteka/UATFramework/pull/79#discussion_r41600735","pull_request_url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79","_links":{"self":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/comments/41600735"},"html":{"href":"https://github.com/aweiteka/UATFramework/pull/79#discussion_r41600735"},"pull_request":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79"}}},"pull_request":{"url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79","id":47106814,"html_url":"https://github.com/aweiteka/UATFramework/pull/79","diff_url":"https://github.com/aweiteka/UATFramework/pull/79.diff","patch_url":"https://github.com/aweiteka/UATFramework/pull/79.patch","issue_url":"https://api.github.com/repos/aweiteka/UATFramework/issues/79","number":79,"state":"open","locked":false,"title":"Add a test for service check","user":{"login":"ypu","id":1137786,"avatar_url":"https://avatars.githubusercontent.com/u/1137786?v=3","gravatar_id":"","url":"https://api.github.com/users/ypu","html_url":"https://github.com/ypu","followers_url":"https://api.github.com/users/ypu/followers","following_url":"https://api.github.com/users/ypu/following{/other_user}","gists_url":"https://api.github.com/users/ypu/gists{/gist_id}","starred_url":"https://api.github.com/users/ypu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ypu/subscriptions","organizations_url":"https://api.github.com/users/ypu/orgs","repos_url":"https://api.github.com/users/ypu/repos","events_url":"https://api.github.com/users/ypu/events{/privacy}","received_events_url":"https://api.github.com/users/ypu/received_events","type":"User","site_admin":false},"body":"Add a test case for the services check.\r\nThe default configuration is for etcd services test. And we can test other services(like docker and so on) by update the cfg files.  ","created_at":"2015-10-08T03:00:08Z","updated_at":"2015-10-09T06:25:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"745d8c571f4a9ca98240ad908cc32c8f27ed4927","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79/commits","review_comments_url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79/comments","review_comment_url":"https://api.github.com/repos/aweiteka/UATFramework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aweiteka/UATFramework/issues/79/comments","statuses_url":"https://api.github.com/repos/aweiteka/UATFramework/statuses/fb8b1b6e5616fbd5464b4efe7679786dfd4cd5d2","head":{"label":"ypu:service_check","ref":"service_check","sha":"fb8b1b6e5616fbd5464b4efe7679786dfd4cd5d2","user":{"login":"ypu","id":1137786,"avatar_url":"https://avatars.githubusercontent.com/u/1137786?v=3","gravatar_id":"","url":"https://api.github.com/users/ypu","html_url":"https://github.com/ypu","followers_url":"https://api.github.com/users/ypu/followers","following_url":"https://api.github.com/users/ypu/following{/other_user}","gists_url":"https://api.github.com/users/ypu/gists{/gist_id}","starred_url":"https://api.github.com/users/ypu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ypu/subscriptions","organizations_url":"https://api.github.com/users/ypu/orgs","repos_url":"https://api.github.com/users/ypu/repos","events_url":"https://api.github.com/users/ypu/events{/privacy}","received_events_url":"https://api.github.com/users/ypu/received_events","type":"User","site_admin":false},"repo":{"id":38678722,"name":"UATFramework","full_name":"ypu/UATFramework","owner":{"login":"ypu","id":1137786,"avatar_url":"https://avatars.githubusercontent.com/u/1137786?v=3","gravatar_id":"","url":"https://api.github.com/users/ypu","html_url":"https://github.com/ypu","followers_url":"https://api.github.com/users/ypu/followers","following_url":"https://api.github.com/users/ypu/following{/other_user}","gists_url":"https://api.github.com/users/ypu/gists{/gist_id}","starred_url":"https://api.github.com/users/ypu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ypu/subscriptions","organizations_url":"https://api.github.com/users/ypu/orgs","repos_url":"https://api.github.com/users/ypu/repos","events_url":"https://api.github.com/users/ypu/events{/privacy}","received_events_url":"https://api.github.com/users/ypu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ypu/UATFramework","description":"A lightweight User Acceptance Testing framework","fork":true,"url":"https://api.github.com/repos/ypu/UATFramework","forks_url":"https://api.github.com/repos/ypu/UATFramework/forks","keys_url":"https://api.github.com/repos/ypu/UATFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ypu/UATFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ypu/UATFramework/teams","hooks_url":"https://api.github.com/repos/ypu/UATFramework/hooks","issue_events_url":"https://api.github.com/repos/ypu/UATFramework/issues/events{/number}","events_url":"https://api.github.com/repos/ypu/UATFramework/events","assignees_url":"https://api.github.com/repos/ypu/UATFramework/assignees{/user}","branches_url":"https://api.github.com/repos/ypu/UATFramework/branches{/branch}","tags_url":"https://api.github.com/repos/ypu/UATFramework/tags","blobs_url":"https://api.github.com/repos/ypu/UATFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ypu/UATFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ypu/UATFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/ypu/UATFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ypu/UATFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/ypu/UATFramework/languages","stargazers_url":"https://api.github.com/repos/ypu/UATFramework/stargazers","contributors_url":"https://api.github.com/repos/ypu/UATFramework/contributors","subscribers_url":"https://api.github.com/repos/ypu/UATFramework/subscribers","subscription_url":"https://api.github.com/repos/ypu/UATFramework/subscription","commits_url":"https://api.github.com/repos/ypu/UATFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/ypu/UATFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/ypu/UATFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/ypu/UATFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/ypu/UATFramework/contents/{+path}","compare_url":"https://api.github.com/repos/ypu/UATFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ypu/UATFramework/merges","archive_url":"https://api.github.com/repos/ypu/UATFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ypu/UATFramework/downloads","issues_url":"https://api.github.com/repos/ypu/UATFramework/issues{/number}","pulls_url":"https://api.github.com/repos/ypu/UATFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/ypu/UATFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/ypu/UATFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ypu/UATFramework/labels{/name}","releases_url":"https://api.github.com/repos/ypu/UATFramework/releases{/id}","created_at":"2015-07-07T09:47:29Z","updated_at":"2015-07-07T09:47:29Z","pushed_at":"2015-10-08T02:27:04Z","git_url":"git://github.com/ypu/UATFramework.git","ssh_url":"git@github.com:ypu/UATFramework.git","clone_url":"https://github.com/ypu/UATFramework.git","svn_url":"https://github.com/ypu/UATFramework","homepage":"","size":276,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"aweiteka:master","ref":"master","sha":"71f8757c077a8e08aaafd5674072e4a0edf88b3f","user":{"login":"aweiteka","id":1764461,"avatar_url":"https://avatars.githubusercontent.com/u/1764461?v=3","gravatar_id":"","url":"https://api.github.com/users/aweiteka","html_url":"https://github.com/aweiteka","followers_url":"https://api.github.com/users/aweiteka/followers","following_url":"https://api.github.com/users/aweiteka/following{/other_user}","gists_url":"https://api.github.com/users/aweiteka/gists{/gist_id}","starred_url":"https://api.github.com/users/aweiteka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aweiteka/subscriptions","organizations_url":"https://api.github.com/users/aweiteka/orgs","repos_url":"https://api.github.com/users/aweiteka/repos","events_url":"https://api.github.com/users/aweiteka/events{/privacy}","received_events_url":"https://api.github.com/users/aweiteka/received_events","type":"User","site_admin":false},"repo":{"id":27437572,"name":"UATFramework","full_name":"aweiteka/UATFramework","owner":{"login":"aweiteka","id":1764461,"avatar_url":"https://avatars.githubusercontent.com/u/1764461?v=3","gravatar_id":"","url":"https://api.github.com/users/aweiteka","html_url":"https://github.com/aweiteka","followers_url":"https://api.github.com/users/aweiteka/followers","following_url":"https://api.github.com/users/aweiteka/following{/other_user}","gists_url":"https://api.github.com/users/aweiteka/gists{/gist_id}","starred_url":"https://api.github.com/users/aweiteka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aweiteka/subscriptions","organizations_url":"https://api.github.com/users/aweiteka/orgs","repos_url":"https://api.github.com/users/aweiteka/repos","events_url":"https://api.github.com/users/aweiteka/events{/privacy}","received_events_url":"https://api.github.com/users/aweiteka/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aweiteka/UATFramework","description":"A lightweight User Acceptance Testing framework","fork":false,"url":"https://api.github.com/repos/aweiteka/UATFramework","forks_url":"https://api.github.com/repos/aweiteka/UATFramework/forks","keys_url":"https://api.github.com/repos/aweiteka/UATFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aweiteka/UATFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aweiteka/UATFramework/teams","hooks_url":"https://api.github.com/repos/aweiteka/UATFramework/hooks","issue_events_url":"https://api.github.com/repos/aweiteka/UATFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aweiteka/UATFramework/events","assignees_url":"https://api.github.com/repos/aweiteka/UATFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aweiteka/UATFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aweiteka/UATFramework/tags","blobs_url":"https://api.github.com/repos/aweiteka/UATFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aweiteka/UATFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aweiteka/UATFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aweiteka/UATFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aweiteka/UATFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aweiteka/UATFramework/languages","stargazers_url":"https://api.github.com/repos/aweiteka/UATFramework/stargazers","contributors_url":"https://api.github.com/repos/aweiteka/UATFramework/contributors","subscribers_url":"https://api.github.com/repos/aweiteka/UATFramework/subscribers","subscription_url":"https://api.github.com/repos/aweiteka/UATFramework/subscription","commits_url":"https://api.github.com/repos/aweiteka/UATFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aweiteka/UATFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aweiteka/UATFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aweiteka/UATFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/aweiteka/UATFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aweiteka/UATFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aweiteka/UATFramework/merges","archive_url":"https://api.github.com/repos/aweiteka/UATFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aweiteka/UATFramework/downloads","issues_url":"https://api.github.com/repos/aweiteka/UATFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aweiteka/UATFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aweiteka/UATFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aweiteka/UATFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aweiteka/UATFramework/labels{/name}","releases_url":"https://api.github.com/repos/aweiteka/UATFramework/releases{/id}","created_at":"2014-12-02T15:01:58Z","updated_at":"2015-04-30T12:43:18Z","pushed_at":"2015-10-08T15:09:38Z","git_url":"git://github.com/aweiteka/UATFramework.git","ssh_url":"git@github.com:aweiteka/UATFramework.git","clone_url":"https://github.com/aweiteka/UATFramework.git","svn_url":"https://github.com/aweiteka/UATFramework","homepage":"","size":742,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":6,"forks":12,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79"},"html":{"href":"https://github.com/aweiteka/UATFramework/pull/79"},"issue":{"href":"https://api.github.com/repos/aweiteka/UATFramework/issues/79"},"comments":{"href":"https://api.github.com/repos/aweiteka/UATFramework/issues/79/comments"},"review_comments":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79/comments"},"review_comment":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aweiteka/UATFramework/pulls/79/commits"},"statuses":{"href":"https://api.github.com/repos/aweiteka/UATFramework/statuses/fb8b1b6e5616fbd5464b4efe7679786dfd4cd5d2"}}}}