Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
interface-openstack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e1cdc179
authored
May 12, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try methods in main.py, start write tests
parent
503b5c02
Pipeline
#710
failed with stage
in 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
7 deletions
+80
-7
main.py
+25
-7
tests/vmtest.py
+55
-0
No files found.
main.py
View file @
e1cdc179
# This file is for testing the openstack api access
from
implementation.vm.instance
import
OSVirtualMachineManager
from
interface.vm.resources
import
BlockDeviceMapping
,
Flavor
import
openstack
# openstack.enable_logging(debug=True)
conn
=
openstack
.
connect
(
cloud
=
'openstack'
)
block_dev_map
=
BlockDeviceMapping
(
boot_index
=
0
,
uuid
=
"da51253f-867c-472d-8ce0-81e7b7126d60"
,
source_type
=
"image"
,
volume_size
=
10
,
destination_type
=
"volume"
,
delete_on_termination
=
True
,
disk_bus
=
"scsi"
)
networks
=
[{
"uuid"
:
"c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"
}]
interface
=
OSVirtualMachineManager
(
conn
)
resource
=
{
"name"
:
"m1.tiny"
,
"ram"
:
1024
,
"cpu"
:
2
}
print
(
'#'
*
40
)
print
(
resource
)
# interface.create_vm_from_template('new_server', resource, "cirros-0.4.0-x86_64-disk")
# interface.stop_vm('a6bc504f-a422-4492-b429-e5dad2df12f4')
server
=
interface
.
get_vm
(
"New test"
)
# server = interface.get_vm("8e94c162-f8ed-4872-b9e5-50bf33040b5b")
# print(interface.delete_flavor("flavorTest"))
for
flavor
in
interface
.
list_flavors
():
print
(
flavor
.
JSON
())
# print(interface.create_base_vm("BaseTest", "2", networks, block_dev_map))
# print(interface.convert_server_to_instance(server).JSON())
print
(
interface
.
convert_server_to_instance
(
server
)
.
JSON
(
))
# print(interface.openstack.compute.get_server("8e94c162-f8ed-4872-b9e5-50bf33040b5b"
))
print
(
interface
.
get_status
(
"Uborka Test"
))
# print(server.JSON(
))
print
(
interface
.
get_vnc_console
(
"8e94c162-f8ed-4872-b9e5-50bf33040b5b"
))
#
print(interface.get_vnc_console("8e94c162-f8ed-4872-b9e5-50bf33040b5b"))
# print(interface.convert_server_to_instance(server))
...
...
@@ -37,4 +56,3 @@ print(interface.get_vnc_console("8e94c162-f8ed-4872-b9e5-50bf33040b5b"))
# interface.wake_up_vm(server.id)
# interface.destroy_vm(server.id)
# conn.compute.change_server_password(server, "root")
tests/vmtest.py
0 → 100644
View file @
e1cdc179
import
unittest
from
unittest.mock
import
MagicMock
from
implementation.vm.instance
import
OSVirtualMachineManager
from
interface.vm.resources
import
Instance
servers
=
[
MagicMock
(
id
=
"test1"
,
name
=
"test1"
,
flavorRef
=
"flav1"
,
imageRef
=
"image1"
,
networks
=
[{
"uuid"
:
"network1"
}],
terminated_at
=
"20200320-15-31"
,
launched_at
=
"20190510-13-22"
,
disks
=
[
"disk1"
],
status
=
"ACTIVE"
,
addresses
=
[{
"mac"
:
"12345678AB"
,
"ipv4"
:
"1.1.1.1"
}]
)
]
class
MockOpenStackCompute
(
MagicMock
):
def
setUp
(
self
):
self
.
compute
=
MagicMock
()
self
.
compute
.
create_server
=
MagicMock
(
return_value
=
servers
[
0
])
self
.
compute
.
find_flavor
=
MagicMock
(
return_value
=
MagicMock
(
id
=
"uuid1"
))
self
.
compute
.
find_image
=
MagicMock
(
return_value
=
MagicMock
(
id
=
"uuid2"
))
self
.
compute
.
wait_for_server
=
MagicMock
(
return_value
=
True
)
self
.
compute
.
list_servers
=
MagicMock
(
return_value
=
servers
)
class
InstanceCreateTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
conn
=
MockOpenStackCompute
()
self
.
conn
.
setUp
()
self
.
manager
=
OSVirtualMachineManager
(
self
.
conn
)
def
tearDown
(
self
):
pass
def
test_create_from_template
(
self
):
instance
=
self
.
manager
.
create_vm_from_template
(
'test'
,
'imageid'
,
'flavorid'
,
[
'networkid1'
])
self
.
conn
.
compute
.
create_server
.
assert_called
()
def
test_create_from_template_params
(
self
):
self
.
manager
.
create_vm_from_template
(
'test'
,
'imageid'
,
'flavorid'
,
[
'networkid1'
])
self
.
conn
.
compute
.
create_server
.
assert_called_with
(
name
=
'test'
,
flavorRef
=
"uuid1"
,
imageRef
=
"uuid2"
,
networks
=
[
'networkid1'
],
min_count
=
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment