6
6
import os
7
7
import threading
8
8
from datetime import datetime
9
- import time
9
+ import redis
10
10
from pprint import pprint
11
11
12
12
remiro_config_template = """
@@ -55,24 +55,19 @@ def random_string(length=8):
55
55
56
56
57
57
def random_id ():
58
- return "{:>3}" .format (random .randrange (999 ))
58
+ return "{:0 >3}" .format (random .randrange (999 ))
59
59
60
60
61
61
if __name__ == "__main__" :
62
- # remiro_config = remiro_config_template.format(
63
- # delete_on_set="true",
64
- # delete_on_get="false",
65
- # src_addr='"127.0.0.1:3456"',
66
- # dst_addr='"127.0.0.1:4567"',
67
- # )
68
- # print(remiro_config)
69
62
70
63
e2e_id = "e2e{}" .format (random_id ())
71
64
print ("e2e_id: {}" .format (e2e_id ))
72
65
73
66
test_id = "tid{}" .format (random_id ())
74
67
print ("test_id: {}" .format (test_id ))
75
68
69
+ redis_version = "redis:5.0.5"
70
+
76
71
remiro_port = 6400
77
72
redis_src_port = 6410
78
73
redis_dst_port = 6420
@@ -121,8 +116,46 @@ def random_id():
121
116
)
122
117
pprint (e2e_test_volume )
123
118
119
+ # === setup volume container: intermediary container to copy files from host to volume ===
120
+ client .images .pull ("hello-world:latest" )
121
+ e2e_test_volume_container = client .containers .create (
122
+ name = "e2e-test-volume-container-{}-{}" .format (e2e_id , test_id ),
123
+ image = "hello-world" ,
124
+ volumes = {e2e_test_volume .name : default_bind_volume },
125
+ )
126
+ # ===
124
127
print ("Creating containers ..." )
125
128
129
+ print ("Creating redis-src container ..." )
130
+ redis_src_container_name = "redis-src-{}-{}" .format (e2e_id , test_id )
131
+ redis_src_container = client .containers .run (
132
+ name = redis_src_container_name ,
133
+ image = redis_version ,
134
+ detach = True ,
135
+ command = "redis-server" ,
136
+ network = e2e_test_network .name ,
137
+ volumes = {e2e_test_volume .name : default_bind_volume },
138
+ # ports={"{}/tcp".format(redis_src_port): redis_src_port},
139
+ ports = {"6379/tcp" : redis_src_port },
140
+ )
141
+ print ("redis-src: " , redis_src_container )
142
+ async_print_container_log (redis_src_container )
143
+
144
+ print ("Creating redis-dst container ..." )
145
+ redis_dst_container_name = "redis-dst-{}-{}" .format (e2e_id , test_id )
146
+ redis_dst_container = client .containers .run (
147
+ name = redis_dst_container_name ,
148
+ image = redis_version ,
149
+ detach = True ,
150
+ command = "redis-server" ,
151
+ network = e2e_test_network .name ,
152
+ volumes = {e2e_test_volume .name : default_bind_volume },
153
+ # ports={"{}/tcp".format(redis_dst_port): redis_dst_port},
154
+ ports = {"6379/tcp" : redis_dst_port },
155
+ )
156
+ print ("redis-dst: " , redis_dst_container )
157
+ async_print_container_log (redis_dst_container )
158
+
126
159
print ("Creating rdb-tools container ..." )
127
160
rdb_tools_container_name = "rdb-tools-{}-{}" .format (e2e_id , test_id )
128
161
rdb_tools_container = client .containers .run (
@@ -134,34 +167,98 @@ def random_id():
134
167
volumes = {e2e_test_volume .name : default_bind_volume },
135
168
)
136
169
print ("rdb-tools: " , rdb_tools_container )
137
-
138
170
async_print_container_log (rdb_tools_container )
139
171
140
172
print ("Creating remiro container ..." )
173
+
174
+ print ("NETWORK:" )
175
+ # e2e_test_network.connect(redis_src_container)
176
+ e2e_test_network .reload ()
177
+ pprint (e2e_test_network .attrs )
178
+
179
+ redis_src_ip = e2e_test_network .attrs ["Containers" ][redis_src_container .id ][
180
+ "IPv4Address"
181
+ ][:- 3 ]
182
+ redis_dst_ip = e2e_test_network .attrs ["Containers" ][redis_dst_container .id ][
183
+ "IPv4Address"
184
+ ][:- 3 ]
185
+
186
+ # === Copy Remiro Config File
187
+
188
+ remiro_config = remiro_config_template .format (
189
+ delete_on_set = "false" ,
190
+ delete_on_get = "false" ,
191
+ src_addr = '"{}:{}"' .format (redis_src_ip , redis_src_port ),
192
+ dst_addr = '"{}:{}"' .format (redis_dst_ip , redis_dst_port ),
193
+ )
194
+ print (remiro_config )
195
+
196
+ remiro_config_path = "{}/config.toml" .format (default_bind_path )
197
+
198
+ temp_dir = tempfile .TemporaryDirectory ()
199
+
200
+ # remiro_config_file = tempfile.NamedTemporaryFile(mode="w+t", delete=False)
201
+ remiro_config_file = open (os .path .join (temp_dir .name , "config.toml" ), mode = "w+" )
202
+ try :
203
+ remiro_config_file .writelines (remiro_config )
204
+ print ("remiro_config_file: " , remiro_config_file .name )
205
+ # remiro_config_file.name = "config.toml"
206
+
207
+ status_put_archive = api_client .put_archive (
208
+ e2e_test_volume_container .name ,
209
+ default_bind_path ,
210
+ simple_tar (remiro_config_file .name ),
211
+ )
212
+ print ("STATUS PUT_ARCHIVE: {}" .format (status_put_archive ))
213
+
214
+ finally :
215
+ remiro_config_file .close ()
216
+
141
217
remiro_container_name = "remiro-{}-{}" .format (e2e_id , test_id )
142
218
remiro_container = client .containers .run (
143
219
name = remiro_container_name ,
144
220
image = remiro_image .id ,
145
221
detach = True ,
146
- command = "-h 0.0.0.0 -p {}" .format (remiro_port ),
222
+ command = "-h 0.0.0.0 -p {} -c {} " .format (remiro_port , remiro_config_path ),
147
223
network = e2e_test_network .name ,
148
224
volumes = {e2e_test_volume .name : default_bind_volume },
149
225
ports = {"{}/tcp" .format (remiro_port ): remiro_port },
150
226
)
151
227
print ("remiro: " , remiro_container )
152
-
228
+ pprint ( remiro_container . attrs )
153
229
async_print_container_log (remiro_container )
154
230
155
- # Delete containers. (Temporarily)
231
+ # === TEST with Redis Client
232
+ # print("REDIS-SRC:")
233
+ # pprint(redis_src_container.attrs)
234
+
235
+ r = redis .Redis (host = "127.0.0.1" , port = remiro_port )
236
+ print (r .set ("foo" , "bar" ))
237
+ print (r .get ("foo" ))
238
+
239
+ # ===
240
+
241
+ # === Delete containers. (Temporarily)
242
+ e2e_test_volume_container .stop ()
243
+ e2e_test_volume_container .remove ()
244
+
156
245
rdb_tools_container .stop ()
157
246
rdb_tools_container .remove ()
158
247
159
- # remiro_container.stop()
160
- # remiro_container.remove()
248
+ remiro_container .stop ()
249
+ remiro_container .remove ()
250
+
251
+ redis_src_container .stop ()
252
+ redis_src_container .remove ()
253
+
254
+ redis_dst_container .stop ()
255
+ redis_dst_container .remove ()
256
+ # ===
161
257
162
258
# Remove images, network
163
259
print ("Removing images, network, volume ..." )
164
- client .images .remove (image = rdb_tools_image .id )
260
+ # client.images.remove(image=rdb_tools_image.id)
165
261
# client.images.remove(image=remiro_image.id)
166
- # e2e_test_network.remove()
167
- # e2e_test_volume.remove()
262
+
263
+ e2e_test_network .remove ()
264
+ e2e_test_volume .remove ()
0 commit comments