[cs615asa] [git commit] CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS) branch main updated. b1d07c6287b8e157e2a495af2d72a773d56c6d96

Git Owner jschauma at stevens.edu
Sun May 9 17:29:09 EDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS)".

The branch, main has been updated
       via  b1d07c6287b8e157e2a495af2d72a773d56c6d96 (commit)
       via  246f92f4a4ea28a4eb5c12a98da58538c4850c52 (commit)
       via  4c2ca0a60080e6e45f03f5f384ccb98fc8e08dd7 (commit)
       via  19d6fde351328a850a8c34bb3538717a3c0ae249 (commit)
      from  6746d7cfc2b5e7730d3ee5148245a2a2b65ba945 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b1d07c6287b8e157e2a495af2d72a773d56c6d96
Merge: 6746d7c 246f92f
Author: ngoldstein51 <ngoldstein51 at gmail.com>
Date:   Sun May 9 17:26:57 2021 -0400

    test cases for mocked volume and ec2

diff --cc .gitignore
index 4ed4301,4ed4301..e230db1
--- a/.gitignore
+++ b/.gitignore
@@@ -2,3 -2,3 +2,4 @@@
  __pycache__/
  **/__pycache__/
  .vscode
++**/ebs_backup.egg-info/
diff --cc test/test_ec2.py
index f2732ee,a426698..76a53be
--- a/test/test_ec2.py
+++ b/test/test_ec2.py
@@@ -2,14 -2,55 +2,55 @@@ import unittes
  import sys
  import os
  from unittest.mock import patch
- from ec2 import EC2
- 
+ import boto3
+ from botocore.exceptions import ClientError
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) # better than sys.path.append("../")
  sys.path.append('..')
+ from src.ec2 import EC2
  
  class EC2Test(unittest.TestCase):
-     def test_example(self):
-         self.assertTrue(True)
- 
+     def test_primitive_check01(self):
+         with patch.object(EC2, "__init__", lambda x, y, z: None):
+           ec2 = EC2(None, None)
+           # self.assertTrue(True)
+           #print("Zehui->>>>>>>>>>>>>",ec2.primitive_check("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe..."))
+           assert ec2.primitive_check("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe...") is False
  
+     def test_primitive_check02(self):
+         with patch.object(EC2, "__init__", lambda x, y, z: None):
+           ec2 = EC2(None, None)
+           # self.assertTrue(True)
+           assert ec2.primitive_check("ResponseMetadata TTPHe...") is True
+           
+           
+     def test_createEC2_01(self):
+         print("----test_createEC2_01-----")
+         with patch.object(EC2, "__init__", lambda x, y, z,w,e: None):
+           
+       
+           args = {
+                       'ImageId': 'ami-0018b2d98332ba7e3',
+                       'MinCount': 1,
+                       'MaxCount': 1,
+                       'InstanceType': 't2.micro',
+                       'KeyName': 'ebs-backup',
+                       'Placement': {"AvailabilityZone": 'us-east-1a'}
+                   }
+           ZONE = 'us-east-1'
+           session = boto3.Session(region_name=ZONE)
+         #   ec2 = EC2(session, {
+         #           'zone_id': ZONE + 'a',
+         #       })
+           ec2_client = session.client('ec2')
+           instance = ec2_client.run_instances(**args)
+           instance_id = instance["Instances"][0]["InstanceId"]
+           ec2 = EC2(None, None,instance,instance_id)
+           print(ec2.instance,"----test_createEC2_01-----")
+           # with patch.object(EC2, "__init__", lambda x, y, z: None):
+           #   ec2 = EC2(None, None)
+           #   print("Zehui->>>>>>>>>>>>>",ec2.parse_overrides("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe..."))
+   
+           assert instance_id is not None
+           
  if __name__ == '__main__':
 -    unittest.main()
 +    unittest.main()

commit 246f92f4a4ea28a4eb5c12a98da58538c4850c52
Author: zehui <zxie11 at stevens.edu>
Date:   Sun May 9 07:58:23 2021 -0400

    zehui

diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 4eae7a7..986e586 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -10,5 +10,6 @@ ngoldste  2021-02-16       yes
 hdevlin   2021-02-22       yes
 ajin1	  2021-02-22	   yes
 camatang  2021-02-20       yes
+zxie11  2021-02-28       yes
 ddelaus   2021-05-05       yes
 jho1      2021-03-08       yes

commit 4c2ca0a60080e6e45f03f5f384ccb98fc8e08dd7
Merge: 19d6fde 0e0bcea
Author: zehui <zxie11 at stevens.edu>
Date:   Sun May 9 07:52:54 2021 -0400

    Merge branch 'main' of cs615asa:~git/ebs-backup into main


commit 19d6fde351328a850a8c34bb3538717a3c0ae249
Author: zehui <zxie11 at stevens.edu>
Date:   Sun May 9 07:38:27 2021 -0400

    zxie

diff --git a/test/test_ec2.py b/test/test_ec2.py
new file mode 100644
index 0000000..a426698
--- /dev/null
+++ b/test/test_ec2.py
@@ -0,0 +1,56 @@
+import unittest
+import sys
+import os
+from unittest.mock import patch
+import boto3
+from botocore.exceptions import ClientError
+sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) # better than sys.path.append("../")
+sys.path.append('..')
+from src.ec2 import EC2
+
+class EC2Test(unittest.TestCase):
+    def test_primitive_check01(self):
+        with patch.object(EC2, "__init__", lambda x, y, z: None):
+          ec2 = EC2(None, None)
+          # self.assertTrue(True)
+          #print("Zehui->>>>>>>>>>>>>",ec2.primitive_check("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe..."))
+          assert ec2.primitive_check("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe...") is False
+
+    def test_primitive_check02(self):
+        with patch.object(EC2, "__init__", lambda x, y, z: None):
+          ec2 = EC2(None, None)
+          # self.assertTrue(True)
+          assert ec2.primitive_check("ResponseMetadata TTPHe...") is True
+          
+          
+    def test_createEC2_01(self):
+        print("----test_createEC2_01-----")
+        with patch.object(EC2, "__init__", lambda x, y, z,w,e: None):
+          
+      
+          args = {
+                      'ImageId': 'ami-0018b2d98332ba7e3',
+                      'MinCount': 1,
+                      'MaxCount': 1,
+                      'InstanceType': 't2.micro',
+                      'KeyName': 'ebs-backup',
+                      'Placement': {"AvailabilityZone": 'us-east-1a'}
+                  }
+          ZONE = 'us-east-1'
+          session = boto3.Session(region_name=ZONE)
+        #   ec2 = EC2(session, {
+        #           'zone_id': ZONE + 'a',
+        #       })
+          ec2_client = session.client('ec2')
+          instance = ec2_client.run_instances(**args)
+          instance_id = instance["Instances"][0]["InstanceId"]
+          ec2 = EC2(None, None,instance,instance_id)
+          print(ec2.instance,"----test_createEC2_01-----")
+          # with patch.object(EC2, "__init__", lambda x, y, z: None):
+          #   ec2 = EC2(None, None)
+          #   print("Zehui->>>>>>>>>>>>>",ec2.parse_overrides("{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHe..."))
+  
+          assert instance_id is not None
+          
+if __name__ == '__main__':
+    unittest.main()
\ No newline at end of file
diff --git a/test/test_volume.py b/test/test_volume.py
new file mode 100644
index 0000000..2856f4f
--- /dev/null
+++ b/test/test_volume.py
@@ -0,0 +1,69 @@
+import unittest
+import sys
+import os
+from unittest.mock import patch
+#import pytest #no pytest used
+import boto3
+from botocore.exceptions import ClientError
+sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) # better than sys.path
+sys.path.append('..')
+
+from src.volume import Volume
+
+instanceid = 'i-076aee001cb41dd2a'
+volume_id = 'vol-009f9237b12b23e1a'
+ZONE = 'us-east-1'
+session = boto3.Session(region_name=ZONE)
+config = {'volume_id': volume_id, 'size': 2048, 'instanceid': instanceid}
+# @pytest.mark.parametrize("input1,input2 ,output", [
+#     [session, config],
+#     [session, None],
+#     [1, 0]
+    
+# ])#no pytest used
+
+
+        
+class VolumeTest(unittest.TestCase):
+    instanceid = 'i-076aee001cb41dd2a'
+    volume_id = 'vol-009f9237b12b23e1a'
+    ZONE = 'us-east-1'
+    session = boto3.Session(region_name=ZONE)
+    config = {'volume_id': volume_id, 'size': 2048, 'instanceid': instanceid}
+    
+    def newinit(self, session, config):
+        self.session = session
+        self.volume_id = config['volume_id']
+        self.device_name="/dev/sdf"
+    
+    #TODO if exist volum
+    def test_attach_to_instance01(self):
+
+        with patch.object(Volume, "__init__",  lambda x, y: None):
+            vol = Volume(None)
+            
+            vol.instanceid = instanceid
+            vol.device_name = "/dev/sdf"
+            Iid = 'i-076aee001cb41dd2a'
+            res2 = session.client('ec2').create_volume(
+                AvailabilityZone='us-east-1a',
+                Size=config['size'],
+            )
+            #print(res2)
+            vol.volume_id = res2['VolumeId']
+            count=0
+            ec2_resource = boto3.resource('ec2')
+            ec2_volume = session.resource('ec2').Volume(volume_id)
+            
+            for instance in ec2_resource.instances.all():
+                for volume in instance.volumes.all():
+                    #print(instance.id, volume.id, volume.volume_type, volume.size)
+                    count+=1
+            vol.ec2_volume =  res2['VolumeId']
+            #print(vol.attach_to_instance(instanceid))
+            #vol.ec2_volume.attach_to_instance(instanceid) TODO :has issue
+            assert res2 is not 0
+
+
+if __name__ == '__main__':
+    unittest.main()
\ No newline at end of file

-----------------------------------------------------------------------

Summary of changes:
 .gitignore          |  1 +
 CONTRIBUTORS        |  1 +
 test/test_ec2.py    | 51 +++++++++++++++++++++++++++++++++++++++-----
 test/test_volume.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 105 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS)


More information about the cs615asa mailing list