Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
2db19479
Commit
2db19479
authored
Dec 29, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed null attributes bug
parent
3ec949cd
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
149 additions
and
27 deletions
+149
-27
ToscaHelper.java
.../main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
+5
-6
ToscaHelperTest.java
...t/java/nl/uva/sne/drip/commons/utils/ToscaHelperTest.java
+110
-0
default_controller.py
...flask-server/sure_tosca/controllers/default_controller.py
+1
-2
tosca_template_service.py
...flask-server/sure_tosca/service/tosca_template_service.py
+14
-2
swagger.yaml
sure_tosca-flask-server/sure_tosca/swagger/swagger.yaml
+2
-2
test_default_controller.py
...a-flask-server/sure_tosca/test/test_default_controller.py
+17
-15
No files found.
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
View file @
2db19479
...
...
@@ -225,8 +225,8 @@ public class ToscaHelper {
List
<
Map
<
String
,
Object
>>
definitions
=
getProvisionInterfaceDefinitions
(
toscaInterfaceTypes
);
Map
<
String
,
Object
>
definition
=
getBestProvisionInterfaceDefinition
(
definitions
);
Map
<
String
,
Object
>
provisionInterface
=
getProvisionInterfaceInstance
(
definition
,
operation
);
return
null
;
vmTopologyMap
.
getNodeTemplate
().
setInterfaces
(
provisionInterface
);
return
vmTopologyMap
;
}
private
Map
<
String
,
Object
>
getBestProvisionInterfaceDefinition
(
List
<
Map
<
String
,
Object
>>
definitions
)
{
...
...
@@ -240,10 +240,9 @@ public class ToscaHelper {
private
Map
<
String
,
Object
>
getProvisionInterfaceInstance
(
Map
<
String
,
Object
>
definition
,
String
operation
)
throws
ApiException
{
String
type
=
definition
.
keySet
().
iterator
().
next
();
String
[]
typeArray
=
type
.
split
(
"."
);
Map
<
String
,
Object
>
provisionInterface
=
api
.
getDefaultInterface
(
String
.
valueOf
(
id
),
type
,
typeArray
[
typeArray
.
length
-
1
],
operation
);
return
null
;
String
[]
typeArray
=
type
.
split
(
"\\."
);
Map
<
String
,
Object
>
provisionInterface
=
api
.
getDefaultInterface
(
String
.
valueOf
(
id
),
type
,
typeArray
[
typeArray
.
length
-
1
].
toLowerCase
(),
operation
);
return
provisionInterface
;
}
}
drip-commons/src/test/java/nl/uva/sne/drip/commons/utils/ToscaHelperTest.java
View file @
2db19479
...
...
@@ -28,10 +28,14 @@ import java.net.HttpURLConnection;
import
java.net.URL
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.Provisioner
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
org.junit.After
;
import
org.junit.AfterClass
;
...
...
@@ -52,6 +56,7 @@ public class ToscaHelperTest {
private
static
ToscaHelper
instance
;
private
static
ToscaTemplate
toscaTemplate
;
private
static
Boolean
serviceUp
;
private
ToscaTemplate
toscaTemplateWithCredentials
;
public
ToscaHelperTest
()
{
}
...
...
@@ -148,4 +153,109 @@ public class ToscaHelperTest {
}
return
true
;
}
/**
* Test of getTemplateVMsForVMTopology method, of class ToscaHelper.
*/
@Test
public
void
testGetTemplateVMsForVMTopology
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getTemplateVMsForVMTopology"
);
List
<
NodeTemplateMap
>
vmTopologyTemplatesMap
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
nodeTemplateMap
:
vmTopologyTemplatesMap
)
{
List
<
NodeTemplateMap
>
result
=
instance
.
getTemplateVMsForVMTopology
(
nodeTemplateMap
);
for
(
NodeTemplateMap
mvmTopology
:
result
)
{
assertEquals
(
"tosca.nodes.ARTICONF.VM.Compute"
,
mvmTopology
.
getNodeTemplate
().
getType
());
}
}
}
}
/**
* Test of setCredentialsInVMTopology method, of class ToscaHelper.
*
* @throws java.lang.Exception
*/
@Test
public
void
testSetCredentialsInVMTopology
()
throws
Exception
{
if
(
serviceUp
)
{
toscaTemplateWithCredentials
=
null
;
System
.
out
.
println
(
"setCredentialsInVMTopology"
);
List
<
NodeTemplateMap
>
vmTopologies
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
String
provider
=
instance
.
getTopologyProvider
(
vmTopologyMap
);
Credential
credential
=
new
Credential
();
credential
.
setCloudProviderName
(
provider
);
credential
.
setProtocol
(
"protocol"
);
Map
<
String
,
String
>
keys
=
new
HashMap
<>();
keys
.
put
(
"key1"
,
"eeeeeeavovfouirveiuvbepuyb8rwqovd8boacbdbvwy8oqry7f08r3euadinanzxcjc078yn0183xoqedw"
);
credential
.
setKeys
(
keys
);
credential
.
setToken
(
"ijwbfciweubfriw"
);
credential
.
setTokenType
(
"passwrd"
);
credential
.
setUser
(
"user"
);
vmTopologyMap
=
instance
.
setCredentialsInVMTopology
(
vmTopologyMap
,
credential
);
toscaTemplateWithCredentials
=
instance
.
setVMTopologyInToscaTemplate
(
toscaTemplate
,
vmTopologyMap
);
}
System
.
err
.
println
(
instance
.
getId
());
instance
.
uploadToscaTemplate
(
toscaTemplateWithCredentials
);
System
.
err
.
println
(
instance
.
getId
());
NodeTemplate
topology_1
=
toscaTemplateWithCredentials
.
getTopologyTemplate
().
getNodeTemplates
().
get
(
"topology_1"
);
Map
<
String
,
Object
>
attributes
=
topology_1
.
getAttributes
();
assertNotNull
(
attributes
);
assertNotNull
(
attributes
.
get
(
"credential"
));
NodeTemplate
topology
=
toscaTemplateWithCredentials
.
getTopologyTemplate
().
getNodeTemplates
().
get
(
"topology_1"
);
attributes
=
topology
.
getAttributes
();
assertNotNull
(
attributes
);
assertNotNull
(
attributes
.
get
(
"credential"
));
List
<
NodeTemplateMap
>
vmTopologiesMaps
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologiesMaps
)
{
Credential
toscaCredentials
=
instance
.
getCredentialsFromVMTopology
(
vmTopologyMap
);
assertNotNull
(
toscaCredentials
);
}
instance
.
uploadToscaTemplate
(
toscaTemplate
);
}
}
/**
* Test of setVMTopologyInToscaTemplate method, of class ToscaHelper.
*/
@Test
public
void
testSetVMTopologyInToscaTemplate
()
{
System
.
out
.
println
(
"setVMTopologyInToscaTemplate"
);
ToscaTemplate
toscaTemplate
=
null
;
NodeTemplateMap
vmTopologyMap
=
null
;
ToscaHelper
instance
=
null
;
ToscaTemplate
expResult
=
null
;
ToscaTemplate
result
=
instance
.
setVMTopologyInToscaTemplate
(
toscaTemplate
,
vmTopologyMap
);
assertEquals
(
expResult
,
result
);
// TODO review the generated test code and remove the default call to fail.
fail
(
"The test case is a prototype."
);
}
/**
* Test of setProvisionerInterfaceInVMTopology method, of class ToscaHelper.
*/
@Test
public
void
testSetProvisionerInterfaceInVMTopology
()
throws
Exception
{
System
.
out
.
println
(
"setProvisionerInterfaceInVMTopology"
);
NodeTemplateMap
vmTopologyMap
=
null
;
Provisioner
provisioner
=
null
;
String
operation
=
""
;
ToscaHelper
instance
=
null
;
NodeTemplateMap
expResult
=
null
;
NodeTemplateMap
result
=
instance
.
setProvisionerInterfaceInVMTopology
(
vmTopologyMap
,
provisioner
,
operation
);
assertEquals
(
expResult
,
result
);
// TODO review the generated test code and remove the default call to fail.
fail
(
"The test case is a prototype."
);
}
}
sure_tosca-flask-server/sure_tosca/controllers/default_controller.py
View file @
2db19479
...
...
@@ -78,7 +78,7 @@ def get_default_interface(id, interface_type, instance_name, operation_name): #
:rtype: Dict[str, object]
"""
res
=
tosca_template_service
.
get_default_interface
(
id
,
interface_type
,
instance_name
,
operation_name
)
res
=
tosca_template_service
.
get_default_interface
(
id
,
interface_type
,
instance_name
,
operation_name
)
if
res
:
return
res
return
'Not Found'
,
404
...
...
@@ -101,7 +101,6 @@ def get_default_node_type(id, node_type, instance_name): # noqa: E501
return
'do some magic!'
def
get_dsl_definitions
(
id
,
anchors
=
None
,
derived_from
=
None
):
# noqa: E501
"""
...
...
sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py
View file @
2db19479
...
...
@@ -76,11 +76,23 @@ def get_tosca_template_dict_by_id(id):
return
tosca_template_dict
def
purge_all_tables
():
node_template_db
.
purge_tables
()
dsl_definitions_db
.
purge_tables
()
relationship_template_db
.
purge_tables
()
interface_types_db
.
purge_tables
()
node_template_db
.
close
()
dsl_definitions_db
.
close
()
relationship_template_db
.
close
()
interface_types_db
.
close
()
def
save
(
file
):
try
:
# tosca_template_file_path = os.path.join(db_dir_path, file.filename)
purge_all_tables
()
dictionary
=
yaml
.
safe_load
(
file
.
stream
)
print
(
yaml
.
dump
(
dictionary
))
tosca_template
=
ToscaTemplate
(
yaml_dict_tpl
=
copy
.
deepcopy
(
dictionary
))
tosca_template_model
=
ToscaTemplateModel
.
from_dict
(
dictionary
)
doc_id
=
tosca_templates_db
.
insert
(
dictionary
)
...
...
@@ -409,7 +421,7 @@ def merge_interfaces(id, interface_type):
if
all_interfaces
is
None
:
return
None
all_inputs
=
{}
all_inputs
=
{}
all_operations
=
{}
for
interface
in
all_interfaces
:
interface
=
interface
[
next
(
iter
(
interface
))]
...
...
sure_tosca-flask-server/sure_tosca/swagger/swagger.yaml
View file @
2db19479
...
...
@@ -126,7 +126,7 @@ paths:
"
405"
:
description
:
"
Invalid
input"
x-swagger-router-controller
:
"
sure_tosca.controllers.default_controller"
/tosca_template/{id}/interface/{interface_type}/default
s
:
/tosca_template/{id}/interface/{interface_type}/default
:
get
:
summary
:
"
"
description
:
"
returns
an
interface
instance
with
the
default
required
values."
...
...
@@ -167,7 +167,7 @@ paths:
"
405"
:
description
:
"
Invalid
input"
x-swagger-router-controller
:
"
sure_tosca.controllers.default_controller"
/tosca_template/{id}/node_types/{node_type}/default
s
:
/tosca_template/{id}/node_types/{node_type}/default
:
get
:
summary
:
"
"
description
:
"
returns
an
node
templaye
instance
with
the
default
required
values."
...
...
sure_tosca-flask-server/sure_tosca/test/test_default_controller.py
View file @
2db19479
...
...
@@ -316,21 +316,6 @@ class TestDefaultController(BaseTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIsInstance
(
response
.
json
,
list
)
# def test_upload_tosca_template(self):
# """Test case for upload_tosca_template
#
# upload a tosca template description file
# """
# data = dict(file=(BytesIO(b'some file data'), 'file.txt'))
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template',
# method='POST',
# data=data,
# content_type='multipart/form-data')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
def
upload_file
(
self
):
tosca_path
=
"../../../TOSCA/"
...
...
@@ -354,6 +339,23 @@ class TestDefaultController(BaseTestCase):
file_id
=
response
.
data
.
decode
(
'utf-8'
)
.
replace
(
'
\n
'
,
''
)
return
file_id
def
test_get_default_interface
(
self
):
"""Test case for get_default_interface
"""
id_example
=
self
.
upload_file
()
query_string
=
[(
'instance_name'
,
'instance_name_example'
),
(
'operation_name'
,
'provision'
)]
response
=
self
.
client
.
open
(
'/tosca-sure/1.0.0/tosca_template/{id}/interface/{interface_type}/default'
.
format
(
id
=
id_example
,
interface_type
=
'tosca.interfaces.ARTICONF.CloudsStorm'
),
method
=
'GET'
,
query_string
=
query_string
)
self
.
assertTrue
(
response
.
is_json
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertIsInstance
(
response
.
json
,
dict
)
if
__name__
==
'__main__'
:
import
unittest
...
...
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