{"action":"created","comment":{"url":"https://api.github.com/repos/storaged-project/storaged/pulls/comments/89623838","pull_request_review_id":10168717,"id":89623838,"diff_hunk":"@@ -0,0 +1,118 @@\n+#!/bin/python3\n+\n+import unittest\n+import storagedtestcase\n+import subprocess\n+import time\n+import dbus\n+import glob\n+import os\n+\n+class StoragedDriveTest(storagedtestcase.StoragedTestCase):\n+    \"\"\"This is Drive related functions unit test\"\"\"\n+\n+    def get_device(self, dev_name):\n+        dev = self.get_object('', '/block_devices/' + os.path.basename(dev_name))\n+        return dev\n+\n+\n+    def get_drive_name(self, device):\n+        drive_name = self.get_property(device, '.Block', 'Drive').split('/')[-1]\n+        return drive_name\n+\n+\n+    def get_drive(self, device):\n+        drive_name = self.get_drive_name(device)\n+        drive = self.get_object('', '/drives/' + os.path.basename(drive_name))\n+        drive_object = dbus.Interface(drive, dbus_interface=self.iface_prefix + '.Drive')\n+        return drive_object\n+\n+    def setUp(self):\n+        # create new fake CD-ROM\n+        subprocess.call(['modprobe', 'scsi_debug'])\n+        dirs = glob.glob('/sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block')\n+\n+        with open('/sys/bus/pseudo/drivers/scsi_debug/ptype', 'w') as f:\n+            f.write('5')  # '5' == created devices will be CD drives\n+        with open('/sys/bus/pseudo/drivers/scsi_debug/num_tgts', 'w') as f:\n+            f.write('1')  # change desired number of new targets to 1\n+        with open('/sys/bus/pseudo/drivers/scsi_debug/add_host', 'w') as f:\n+            f.write('1')  # generate a new device (add_host also applies changes)\n+        subprocess.call(['udevadm', 'settle'])\n+\n+        new_dirs = []\n+        # rescan directories; we cannot tell which file is the new one...\n+        while len(new_dirs) < len(dirs) + 1:\n+            new_dirs = glob.glob('/sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block')\n+            time.sleep(0.1)\n+\n+        # ...so we just diff all devices with the previous scan result to get the new one\n+        new_dirs = list(set(new_dirs) - set(dirs))\n+        assert len(new_dirs) == 1\n+\n+        self.cd_dev = os.listdir(new_dirs[0])\n+        assert len(self.cd_dev) == 1\n+        self.cd_dev = '/dev/' + self.cd_dev[0]\n+        assert os.path.exists(self.cd_dev)\n+\n+        self.cd_device = self.get_device(self.cd_dev)\n+        self.cd_drive_name = self.get_drive_name(self.cd_device)\n+        self.cd_drive = self.get_drive(self.cd_device)\n+\n+\n+    def tearDown(self):\n+        device = self.cd_dev.split('/')[-1]\n+        if os.path.exists('/sys/block/' + device):\n+            with open('/sys/block/%s/device/delete' % device, 'w') as f:\n+                f.write('1')\n+            while os.path.exists(device):\n+                time.sleep(0.1)\n+            subprocess.call(['udevadm', 'settle'])\n+            subprocess.call(['modprobe', '-r', 'scsi_debug'])\n+\n+\n+    def test_10_eject(self):\n+        ''' Test of Drive.Eject method '''\n+        # when new ejectable device is added using scsi_debug,\n+        # it affects already existing virtual devices making some of them\n+        # ejectable as well; this is a workaround\n+\n+        for d in self.vdevs + [self.cd_dev]:\n+            dev = self.get_device(d)\n+            drive = self.get_drive(dev)\n+            drive_name = self.get_drive_name(dev)\n+            if drive_name == self.cd_drive_name:\n+                # ejectable devices should support the Eject function\n+                try:\n+                    drive.Eject(self.no_options)\n+                except Exception:\n+                    self.fail(\"An exception occured while calling Eject function\")\n+            else:\n+                # not ejectable devices should try to run bash command and fail\n+                # with specific exception description\n+                with self.assertRaisesRegex(dbus.exceptions.DBusException,\n+                        'is not hot-pluggable device'):\n+                    drive.Eject(self.no_options)\n+\n+\n+    def test_20_poweroff(self):\n+        ''' Test of Drive.PowerOff method '''\n+        for d in self.vdevs + [self.cd_dev]:\n+            device = self.get_device(d)\n+            drive =  self.get_drive(device)\n+\n+            # check should fail since device cannot be powered off\n+            # sadly so far the only way we can test this function\n+            with self.assertRaisesRegex(dbus.exceptions.DBusException,\n+                    'Failed: No usb device'):\n+                drive.PowerOff(self.no_options)\n+\n+\n+    def test_30_setconfiguration(self):\n+        ''' Test of Drive.SetConfiguration method '''\n+        # set configuration value to some improbable value\n+        self.cd_drive.SetConfiguration({'ata-pm-standby': 286}, self.no_options)\n+\n+        # validate that configration property has changed\n+        conf_value = self.get_property(self.cd_drive, '.Drive', 'Configuration')\n+        self.assertEqual(str(conf_value['ata-pm-standby']), '286')","path":"src/tests/dbus-tests/test_40_drive.py","position":93,"original_position":118,"commit_id":"3374cb704305f81301ba6c03416690cdda3ddef7","original_commit_id":"bd454171ee7d4b06293ebb99c9786476ddf023bd","user":{"login":"japokorn","id":14925901,"avatar_url":"https://avatars.githubusercontent.com/u/14925901?v=3","gravatar_id":"","url":"https://api.github.com/users/japokorn","html_url":"https://github.com/japokorn","followers_url":"https://api.github.com/users/japokorn/followers","following_url":"https://api.github.com/users/japokorn/following{/other_user}","gists_url":"https://api.github.com/users/japokorn/gists{/gist_id}","starred_url":"https://api.github.com/users/japokorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japokorn/subscriptions","organizations_url":"https://api.github.com/users/japokorn/orgs","repos_url":"https://api.github.com/users/japokorn/repos","events_url":"https://api.github.com/users/japokorn/events{/privacy}","received_events_url":"https://api.github.com/users/japokorn/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2016-11-25T14:21:29Z","updated_at":"2016-11-25T14:21:29Z","html_url":"https://github.com/storaged-project/storaged/pull/126#discussion_r89623838","pull_request_url":"https://api.github.com/repos/storaged-project/storaged/pulls/126","_links":{"self":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/comments/89623838"},"html":{"href":"https://github.com/storaged-project/storaged/pull/126#discussion_r89623838"},"pull_request":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/126"}}},"pull_request":{"url":"https://api.github.com/repos/storaged-project/storaged/pulls/126","id":91937318,"html_url":"https://github.com/storaged-project/storaged/pull/126","diff_url":"https://github.com/storaged-project/storaged/pull/126.diff","patch_url":"https://github.com/storaged-project/storaged/pull/126.patch","issue_url":"https://api.github.com/repos/storaged-project/storaged/issues/126","number":126,"state":"open","locked":false,"title":"Added drive and swapspace tests","user":{"login":"japokorn","id":14925901,"avatar_url":"https://avatars.githubusercontent.com/u/14925901?v=3","gravatar_id":"","url":"https://api.github.com/users/japokorn","html_url":"https://github.com/japokorn","followers_url":"https://api.github.com/users/japokorn/followers","following_url":"https://api.github.com/users/japokorn/following{/other_user}","gists_url":"https://api.github.com/users/japokorn/gists{/gist_id}","starred_url":"https://api.github.com/users/japokorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japokorn/subscriptions","organizations_url":"https://api.github.com/users/japokorn/orgs","repos_url":"https://api.github.com/users/japokorn/repos","events_url":"https://api.github.com/users/japokorn/events{/privacy}","received_events_url":"https://api.github.com/users/japokorn/received_events","type":"User","site_admin":false},"body":"added tests for following Dbus api functions:\r\n        * Drive.Eject\r\n        * Drive.PowerOff\r\n        * Drive.SetConfiguration\r\n        * Swapspace.Start\r\n        * Swapspace.Stop","created_at":"2016-11-02T09:48:44Z","updated_at":"2016-11-25T14:21:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00ca5f1dfe57e8b1006c5f44de212b5471dd5589","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/storaged-project/storaged/pulls/126/commits","review_comments_url":"https://api.github.com/repos/storaged-project/storaged/pulls/126/comments","review_comment_url":"https://api.github.com/repos/storaged-project/storaged/pulls/comments{/number}","comments_url":"https://api.github.com/repos/storaged-project/storaged/issues/126/comments","statuses_url":"https://api.github.com/repos/storaged-project/storaged/statuses/3374cb704305f81301ba6c03416690cdda3ddef7","head":{"label":"japokorn:master_dbus_tests","ref":"master_dbus_tests","sha":"3374cb704305f81301ba6c03416690cdda3ddef7","user":{"login":"japokorn","id":14925901,"avatar_url":"https://avatars.githubusercontent.com/u/14925901?v=3","gravatar_id":"","url":"https://api.github.com/users/japokorn","html_url":"https://github.com/japokorn","followers_url":"https://api.github.com/users/japokorn/followers","following_url":"https://api.github.com/users/japokorn/following{/other_user}","gists_url":"https://api.github.com/users/japokorn/gists{/gist_id}","starred_url":"https://api.github.com/users/japokorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japokorn/subscriptions","organizations_url":"https://api.github.com/users/japokorn/orgs","repos_url":"https://api.github.com/users/japokorn/repos","events_url":"https://api.github.com/users/japokorn/events{/privacy}","received_events_url":"https://api.github.com/users/japokorn/received_events","type":"User","site_admin":false},"repo":{"id":72624440,"name":"storaged","full_name":"japokorn/storaged","owner":{"login":"japokorn","id":14925901,"avatar_url":"https://avatars.githubusercontent.com/u/14925901?v=3","gravatar_id":"","url":"https://api.github.com/users/japokorn","html_url":"https://github.com/japokorn","followers_url":"https://api.github.com/users/japokorn/followers","following_url":"https://api.github.com/users/japokorn/following{/other_user}","gists_url":"https://api.github.com/users/japokorn/gists{/gist_id}","starred_url":"https://api.github.com/users/japokorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japokorn/subscriptions","organizations_url":"https://api.github.com/users/japokorn/orgs","repos_url":"https://api.github.com/users/japokorn/repos","events_url":"https://api.github.com/users/japokorn/events{/privacy}","received_events_url":"https://api.github.com/users/japokorn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/japokorn/storaged","description":"The Storaged project provides a daemon, tools and libraries to access and manipulate disks, storage devices and technologies.","fork":true,"url":"https://api.github.com/repos/japokorn/storaged","forks_url":"https://api.github.com/repos/japokorn/storaged/forks","keys_url":"https://api.github.com/repos/japokorn/storaged/keys{/key_id}","collaborators_url":"https://api.github.com/repos/japokorn/storaged/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/japokorn/storaged/teams","hooks_url":"https://api.github.com/repos/japokorn/storaged/hooks","issue_events_url":"https://api.github.com/repos/japokorn/storaged/issues/events{/number}","events_url":"https://api.github.com/repos/japokorn/storaged/events","assignees_url":"https://api.github.com/repos/japokorn/storaged/assignees{/user}","branches_url":"https://api.github.com/repos/japokorn/storaged/branches{/branch}","tags_url":"https://api.github.com/repos/japokorn/storaged/tags","blobs_url":"https://api.github.com/repos/japokorn/storaged/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/japokorn/storaged/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/japokorn/storaged/git/refs{/sha}","trees_url":"https://api.github.com/repos/japokorn/storaged/git/trees{/sha}","statuses_url":"https://api.github.com/repos/japokorn/storaged/statuses/{sha}","languages_url":"https://api.github.com/repos/japokorn/storaged/languages","stargazers_url":"https://api.github.com/repos/japokorn/storaged/stargazers","contributors_url":"https://api.github.com/repos/japokorn/storaged/contributors","subscribers_url":"https://api.github.com/repos/japokorn/storaged/subscribers","subscription_url":"https://api.github.com/repos/japokorn/storaged/subscription","commits_url":"https://api.github.com/repos/japokorn/storaged/commits{/sha}","git_commits_url":"https://api.github.com/repos/japokorn/storaged/git/commits{/sha}","comments_url":"https://api.github.com/repos/japokorn/storaged/comments{/number}","issue_comment_url":"https://api.github.com/repos/japokorn/storaged/issues/comments{/number}","contents_url":"https://api.github.com/repos/japokorn/storaged/contents/{+path}","compare_url":"https://api.github.com/repos/japokorn/storaged/compare/{base}...{head}","merges_url":"https://api.github.com/repos/japokorn/storaged/merges","archive_url":"https://api.github.com/repos/japokorn/storaged/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/japokorn/storaged/downloads","issues_url":"https://api.github.com/repos/japokorn/storaged/issues{/number}","pulls_url":"https://api.github.com/repos/japokorn/storaged/pulls{/number}","milestones_url":"https://api.github.com/repos/japokorn/storaged/milestones{/number}","notifications_url":"https://api.github.com/repos/japokorn/storaged/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/japokorn/storaged/labels{/name}","releases_url":"https://api.github.com/repos/japokorn/storaged/releases{/id}","deployments_url":"https://api.github.com/repos/japokorn/storaged/deployments","created_at":"2016-11-02T09:31:45Z","updated_at":"2016-11-02T09:31:48Z","pushed_at":"2016-11-25T14:18:44Z","git_url":"git://github.com/japokorn/storaged.git","ssh_url":"git@github.com:japokorn/storaged.git","clone_url":"https://github.com/japokorn/storaged.git","svn_url":"https://github.com/japokorn/storaged","homepage":"","size":5824,"stargazers_count":0,"watchers_count":0,"language":"C","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":"storaged-project:master","ref":"master","sha":"ecf04bf6254e7e610d11fd6858912e159a0c0db0","user":{"login":"storaged-project","id":11505466,"avatar_url":"https://avatars.githubusercontent.com/u/11505466?v=3","gravatar_id":"","url":"https://api.github.com/users/storaged-project","html_url":"https://github.com/storaged-project","followers_url":"https://api.github.com/users/storaged-project/followers","following_url":"https://api.github.com/users/storaged-project/following{/other_user}","gists_url":"https://api.github.com/users/storaged-project/gists{/gist_id}","starred_url":"https://api.github.com/users/storaged-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/storaged-project/subscriptions","organizations_url":"https://api.github.com/users/storaged-project/orgs","repos_url":"https://api.github.com/users/storaged-project/repos","events_url":"https://api.github.com/users/storaged-project/events{/privacy}","received_events_url":"https://api.github.com/users/storaged-project/received_events","type":"Organization","site_admin":false},"repo":{"id":31362286,"name":"storaged","full_name":"storaged-project/storaged","owner":{"login":"storaged-project","id":11505466,"avatar_url":"https://avatars.githubusercontent.com/u/11505466?v=3","gravatar_id":"","url":"https://api.github.com/users/storaged-project","html_url":"https://github.com/storaged-project","followers_url":"https://api.github.com/users/storaged-project/followers","following_url":"https://api.github.com/users/storaged-project/following{/other_user}","gists_url":"https://api.github.com/users/storaged-project/gists{/gist_id}","starred_url":"https://api.github.com/users/storaged-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/storaged-project/subscriptions","organizations_url":"https://api.github.com/users/storaged-project/orgs","repos_url":"https://api.github.com/users/storaged-project/repos","events_url":"https://api.github.com/users/storaged-project/events{/privacy}","received_events_url":"https://api.github.com/users/storaged-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/storaged-project/storaged","description":"The Storaged project provides a daemon, tools and libraries to access and manipulate disks, storage devices and technologies.","fork":false,"url":"https://api.github.com/repos/storaged-project/storaged","forks_url":"https://api.github.com/repos/storaged-project/storaged/forks","keys_url":"https://api.github.com/repos/storaged-project/storaged/keys{/key_id}","collaborators_url":"https://api.github.com/repos/storaged-project/storaged/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/storaged-project/storaged/teams","hooks_url":"https://api.github.com/repos/storaged-project/storaged/hooks","issue_events_url":"https://api.github.com/repos/storaged-project/storaged/issues/events{/number}","events_url":"https://api.github.com/repos/storaged-project/storaged/events","assignees_url":"https://api.github.com/repos/storaged-project/storaged/assignees{/user}","branches_url":"https://api.github.com/repos/storaged-project/storaged/branches{/branch}","tags_url":"https://api.github.com/repos/storaged-project/storaged/tags","blobs_url":"https://api.github.com/repos/storaged-project/storaged/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/storaged-project/storaged/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/storaged-project/storaged/git/refs{/sha}","trees_url":"https://api.github.com/repos/storaged-project/storaged/git/trees{/sha}","statuses_url":"https://api.github.com/repos/storaged-project/storaged/statuses/{sha}","languages_url":"https://api.github.com/repos/storaged-project/storaged/languages","stargazers_url":"https://api.github.com/repos/storaged-project/storaged/stargazers","contributors_url":"https://api.github.com/repos/storaged-project/storaged/contributors","subscribers_url":"https://api.github.com/repos/storaged-project/storaged/subscribers","subscription_url":"https://api.github.com/repos/storaged-project/storaged/subscription","commits_url":"https://api.github.com/repos/storaged-project/storaged/commits{/sha}","git_commits_url":"https://api.github.com/repos/storaged-project/storaged/git/commits{/sha}","comments_url":"https://api.github.com/repos/storaged-project/storaged/comments{/number}","issue_comment_url":"https://api.github.com/repos/storaged-project/storaged/issues/comments{/number}","contents_url":"https://api.github.com/repos/storaged-project/storaged/contents/{+path}","compare_url":"https://api.github.com/repos/storaged-project/storaged/compare/{base}...{head}","merges_url":"https://api.github.com/repos/storaged-project/storaged/merges","archive_url":"https://api.github.com/repos/storaged-project/storaged/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/storaged-project/storaged/downloads","issues_url":"https://api.github.com/repos/storaged-project/storaged/issues{/number}","pulls_url":"https://api.github.com/repos/storaged-project/storaged/pulls{/number}","milestones_url":"https://api.github.com/repos/storaged-project/storaged/milestones{/number}","notifications_url":"https://api.github.com/repos/storaged-project/storaged/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/storaged-project/storaged/labels{/name}","releases_url":"https://api.github.com/repos/storaged-project/storaged/releases{/id}","deployments_url":"https://api.github.com/repos/storaged-project/storaged/deployments","created_at":"2015-02-26T10:34:18Z","updated_at":"2016-11-04T14:46:54Z","pushed_at":"2016-11-25T14:18:45Z","git_url":"git://github.com/storaged-project/storaged.git","ssh_url":"git@github.com:storaged-project/storaged.git","clone_url":"https://github.com/storaged-project/storaged.git","svn_url":"https://github.com/storaged-project/storaged","homepage":"","size":6118,"stargazers_count":32,"watchers_count":32,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":22,"forks":21,"open_issues":22,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/126"},"html":{"href":"https://github.com/storaged-project/storaged/pull/126"},"issue":{"href":"https://api.github.com/repos/storaged-project/storaged/issues/126"},"comments":{"href":"https://api.github.com/repos/storaged-project/storaged/issues/126/comments"},"review_comments":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/126/comments"},"review_comment":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/storaged-project/storaged/pulls/126/commits"},"statuses":{"href":"https://api.github.com/repos/storaged-project/storaged/statuses/3374cb704305f81301ba6c03416690cdda3ddef7"}}}}
{"actor":{"display_login":"japokorn"}}