@@ -32,26 +32,68 @@ class GetConfigdriveTestCase(base.IronicAgentTest):
32
32
33
33
@mock .patch .object (gzip , 'GzipFile' , autospec = True )
34
34
def test_get_configdrive (self , mock_gzip , mock_requests , mock_copy ):
35
- mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' )
35
+ mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' ,
36
+ status_code = 200 )
36
37
tempdir = tempfile .mkdtemp ()
37
38
(size , path ) = partition_utils .get_configdrive ('http://1.2.3.4/cd' ,
38
39
'fake-node-uuid' ,
39
40
tempdir = tempdir )
40
41
self .assertTrue (path .startswith (tempdir ))
41
- mock_requests .assert_called_once_with ('http://1.2.3.4/cd' )
42
+ mock_requests .assert_called_once_with ('http://1.2.3.4/cd' ,
43
+ verify = True , cert = None ,
44
+ timeout = 60 )
45
+ mock_gzip .assert_called_once_with ('configdrive' , 'rb' ,
46
+ fileobj = mock .ANY )
47
+ mock_copy .assert_called_once_with (mock .ANY , mock .ANY )
48
+
49
+ @mock .patch .object (gzip , 'GzipFile' , autospec = True )
50
+ def test_get_configdrive_insecure (self , mock_gzip , mock_requests ,
51
+ mock_copy ):
52
+ self .config (insecure = True )
53
+ mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' ,
54
+ status_code = 200 )
55
+ tempdir = tempfile .mkdtemp ()
56
+ (size , path ) = partition_utils .get_configdrive ('http://1.2.3.4/cd' ,
57
+ 'fake-node-uuid' ,
58
+ tempdir = tempdir )
59
+ self .assertTrue (path .startswith (tempdir ))
60
+ mock_requests .assert_called_once_with ('http://1.2.3.4/cd' ,
61
+ verify = False , cert = None ,
62
+ timeout = 60 )
63
+ mock_gzip .assert_called_once_with ('configdrive' , 'rb' ,
64
+ fileobj = mock .ANY )
65
+ mock_copy .assert_called_once_with (mock .ANY , mock .ANY )
66
+
67
+ @mock .patch .object (gzip , 'GzipFile' , autospec = True )
68
+ def test_get_configdrive_ssl (self , mock_gzip , mock_requests , mock_copy ):
69
+ self .config (cafile = 'cafile' , keyfile = 'keyfile' , certfile = 'certfile' )
70
+ mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' ,
71
+ status_code = 200 )
72
+ tempdir = tempfile .mkdtemp ()
73
+ (size , path ) = partition_utils .get_configdrive ('http://1.2.3.4/cd' ,
74
+ 'fake-node-uuid' ,
75
+ tempdir = tempdir )
76
+ self .assertTrue (path .startswith (tempdir ))
77
+ mock_requests .assert_called_once_with ('http://1.2.3.4/cd' ,
78
+ verify = 'cafile' ,
79
+ cert = ('certfile' , 'keyfile' ),
80
+ timeout = 60 )
42
81
mock_gzip .assert_called_once_with ('configdrive' , 'rb' ,
43
82
fileobj = mock .ANY )
44
83
mock_copy .assert_called_once_with (mock .ANY , mock .ANY )
45
84
46
85
def test_get_configdrive_binary (self , mock_requests , mock_copy ):
47
- mock_requests .return_value = mock .MagicMock (content = b'content' )
86
+ mock_requests .return_value = mock .MagicMock (content = b'content' ,
87
+ status_code = 200 )
48
88
tempdir = tempfile .mkdtemp ()
49
89
(size , path ) = partition_utils .get_configdrive ('http://1.2.3.4/cd' ,
50
90
'fake-node-uuid' ,
51
91
tempdir = tempdir )
52
92
self .assertTrue (path .startswith (tempdir ))
53
93
self .assertEqual (b'content' , open (path , 'rb' ).read ())
54
- mock_requests .assert_called_once_with ('http://1.2.3.4/cd' )
94
+ mock_requests .assert_called_once_with ('http://1.2.3.4/cd' ,
95
+ verify = True , cert = None ,
96
+ timeout = 60 )
55
97
self .assertFalse (mock_copy .called )
56
98
57
99
@mock .patch .object (gzip , 'GzipFile' , autospec = True )
@@ -70,6 +112,14 @@ def test_get_configdrive_bad_url(self, mock_requests, mock_copy):
70
112
'http://1.2.3.4/cd' , 'fake-node-uuid' )
71
113
self .assertFalse (mock_copy .called )
72
114
115
+ def test_get_configdrive_bad_status_code (self , mock_requests , mock_copy ):
116
+ mock_requests .return_value = mock .MagicMock (text = 'Not found' ,
117
+ status_code = 404 )
118
+ self .assertRaises (exception .InstanceDeployFailure ,
119
+ partition_utils .get_configdrive ,
120
+ 'http://1.2.3.4/cd' , 'fake-node-uuid' )
121
+ self .assertFalse (mock_copy .called )
122
+
73
123
def test_get_configdrive_base64_error (self , mock_requests , mock_copy ):
74
124
self .assertRaises (exception .InstanceDeployFailure ,
75
125
partition_utils .get_configdrive ,
@@ -79,12 +129,15 @@ def test_get_configdrive_base64_error(self, mock_requests, mock_copy):
79
129
@mock .patch .object (gzip , 'GzipFile' , autospec = True )
80
130
def test_get_configdrive_gzip_error (self , mock_gzip , mock_requests ,
81
131
mock_copy ):
82
- mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' )
132
+ mock_requests .return_value = mock .MagicMock (content = 'Zm9vYmFy' ,
133
+ status_code = 200 )
83
134
mock_copy .side_effect = IOError
84
135
self .assertRaises (exception .InstanceDeployFailure ,
85
136
partition_utils .get_configdrive ,
86
137
'http://1.2.3.4/cd' , 'fake-node-uuid' )
87
- mock_requests .assert_called_once_with ('http://1.2.3.4/cd' )
138
+ mock_requests .assert_called_once_with ('http://1.2.3.4/cd' ,
139
+ verify = True , cert = None ,
140
+ timeout = 60 )
88
141
mock_gzip .assert_called_once_with ('configdrive' , 'rb' ,
89
142
fileobj = mock .ANY )
90
143
mock_copy .assert_called_once_with (mock .ANY , mock .ANY )
0 commit comments