From 1ea7752a0364695cf8bd44b154f527dd0a890435 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Thu, 23 Mar 2023 14:49:28 +0100 Subject: [PATCH 1/4] return service name --- .../add_service/add_service.go | 2 +- .../add_service/add_service_shared.go | 4 ++-- .../startosis_engine/kurtosis_types/service.go | 16 +++++++++------- .../kurtosis_types/service_test.go | 5 +++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service.go index 2f8ff90faf..c683b5ebcc 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service.go @@ -109,7 +109,7 @@ func (builtin *AddServiceCapabilities) Interpret(arguments *builtin_argument.Arg return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to create runtime value to hold '%v' command return values", AddServiceBuiltinName) } - returnValue, interpretationErr := makeAddServiceInterpretationReturnValue(builtin.serviceConfig, builtin.resultUuid) + returnValue, interpretationErr := makeAddServiceInterpretationReturnValue(serviceName, builtin.serviceConfig, builtin.resultUuid) if interpretationErr != nil { return nil, interpretationErr } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go index 7ceaf43fe2..de108d7b4f 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go @@ -34,7 +34,7 @@ func fillAddServiceReturnValueWithRuntimeValues(service *service.Service, result }) } -func makeAddServiceInterpretationReturnValue(serviceConfig *kurtosis_core_rpc_api_bindings.ServiceConfig, resultUuid string) (*kurtosis_types.Service, *startosis_errors.InterpretationError) { +func makeAddServiceInterpretationReturnValue(serviceName starlark.String, serviceConfig *kurtosis_core_rpc_api_bindings.ServiceConfig, resultUuid string) (*kurtosis_types.Service, *startosis_errors.InterpretationError) { ports := serviceConfig.GetPrivatePorts() portSpecsDict := starlark.NewDict(len(ports)) for portId, port := range ports { @@ -54,7 +54,7 @@ func makeAddServiceInterpretationReturnValue(serviceConfig *kurtosis_core_rpc_ap } ipAddress := starlark.String(fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, resultUuid, ipAddressRuntimeValue)) hostname := starlark.String(fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, resultUuid, hostnameRuntimeValue)) - returnValue := kurtosis_types.NewService(hostname, ipAddress, portSpecsDict) + returnValue := kurtosis_types.NewService(serviceName, hostname, ipAddress, portSpecsDict) return returnValue, nil } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/service.go b/core/server/api_container/server/startosis_engine/kurtosis_types/service.go index a447f9fa5a..b4b5604e3d 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_types/service.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_types/service.go @@ -10,9 +10,10 @@ import ( const ( serviceTypeName = "Service" - hostnameAttr = "hostname" - ipAddressAttr = "ip_address" - portsAttr = "ports" + hostnameAttr = "hostname" + ipAddressAttr = "ip_address" + portsAttr = "ports" + serviceNameAttr = "name" ) // Service is just a wrapper around a regular starlarkstruct.Struct @@ -21,11 +22,12 @@ type Service struct { *starlarkstruct.Struct } -func NewService(hostname starlark.String, ipAddress starlark.String, ports *starlark.Dict) *Service { +func NewService(serviceName starlark.String, hostname starlark.String, ipAddress starlark.String, ports *starlark.Dict) *Service { structDict := starlark.StringDict{ - hostnameAttr: hostname, - ipAddressAttr: ipAddress, - portsAttr: ports, + serviceNameAttr: serviceName, + hostnameAttr: hostname, + ipAddressAttr: ipAddress, + portsAttr: ports, } return &Service{ Struct: starlarkstruct.FromStringDict(starlark.String(serviceTypeName), structDict), diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go b/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go index 155d3c8a62..cb1f45a92a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go @@ -14,6 +14,7 @@ const ( testInvalidAttr = "invalid-test-attr" httpApplicationProtocol = "http" emptyApplicationProtocol = "" + serviceNameTestValue = starlark.String("serviceName") ) func TestService_StringRepresentation(t *testing.T) { @@ -90,7 +91,7 @@ func createTestServiceType() (*Service, error) { if err := ports.SetKey(starlark.String("grpc"), portSpec); err != nil { return nil, err } - service := NewService(hostnameTestValue, ipAddressTestValue, ports) + service := NewService(serviceNameTestValue, hostnameTestValue, ipAddressTestValue, ports) return service, nil } @@ -103,6 +104,6 @@ func createTestServiceTypeWithApplicationProtocol() (*Service, error) { if err := ports.SetKey(starlark.String("grpc"), portSpec); err != nil { return nil, err } - service := NewService(hostnameTestValue, ipAddressTestValue, ports) + service := NewService(serviceNameTestValue, hostnameTestValue, ipAddressTestValue, ports) return service, nil } From 2346f8833321ed79ea2256a50f29c4f6089d1ad9 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Thu, 23 Mar 2023 14:51:59 +0100 Subject: [PATCH 2/4] tests pass --- .../kurtosis_instruction/add_service/add_services.go | 2 +- .../test_engine/add_service_framework_test.go | 2 +- .../startosis_engine/kurtosis_types/service_test.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_services.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_services.go index b82850a97e..3e30686fcb 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_services.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_services.go @@ -306,7 +306,7 @@ func makeAddServicesInterpretationReturnValue(serviceConfigs map[service.Service if err != nil { return nil, nil, startosis_errors.WrapWithInterpretationError(err, "Unable to create runtime value to hold '%v' command return values", AddServicesBuiltinName) } - serviceObject, interpretationErr := makeAddServiceInterpretationReturnValue(serviceConfig, resultUuids[serviceName]) + serviceObject, interpretationErr := makeAddServiceInterpretationReturnValue(serviceNameStr, serviceConfig, resultUuids[serviceName]) if interpretationErr != nil { return nil, nil, interpretationErr } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go index 29f49a5b54..10fae441b1 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go @@ -156,7 +156,7 @@ func (t *addServiceTestCase) Assert(interpretationResult starlark.Value, executi serviceObj, ok := interpretationResult.(*kurtosis_types.Service) require.True(t, ok, "interpretation result should be a dictionary") require.NotNil(t, serviceObj) - expectedServiceObj := fmt.Sprintf(`Service\(hostname = "{{kurtosis:[0-9a-f]{32}:hostname.runtime_value}}", ip_address = "{{kurtosis:[0-9a-f]{32}:ip_address.runtime_value}}", ports = {%q: PortSpec\(number=%d, transport_protocol=%q, application_protocol=%q\)}\)`, TestPrivatePortId, TestPrivatePortNumber, TestPrivatePortProtocolStr, TestPrivateApplicationProtocol) + expectedServiceObj := fmt.Sprintf(`Service\(hostname = "{{kurtosis:[0-9a-f]{32}:hostname.runtime_value}}", ip_address = "{{kurtosis:[0-9a-f]{32}:ip_address.runtime_value}}", name = "%v", ports = {%q: PortSpec\(number=%d, transport_protocol=%q, application_protocol=%q\)}\)`, TestServiceName, TestPrivatePortId, TestPrivatePortNumber, TestPrivatePortProtocolStr, TestPrivateApplicationProtocol) require.Regexp(t, expectedServiceObj, serviceObj.String()) expectedExecutionResult := fmt.Sprintf("Service '%s' added with service UUID '%s'", TestServiceName, TestServiceUuid) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go b/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go index cb1f45a92a..df4790ee15 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_types/service_test.go @@ -14,20 +14,20 @@ const ( testInvalidAttr = "invalid-test-attr" httpApplicationProtocol = "http" emptyApplicationProtocol = "" - serviceNameTestValue = starlark.String("serviceName") + serviceNameTestValue = starlark.String("test-service") ) func TestService_StringRepresentation(t *testing.T) { service, err := createTestServiceType() require.Nil(t, err) - expectedStr := `Service(hostname = "datastore-1", ip_address = "{{kurtosis:service_name.ip_address}}", ports = {"grpc": PortSpec(number=123, transport_protocol="TCP")})` + expectedStr := `Service(hostname = "datastore-1", ip_address = "{{kurtosis:service_name.ip_address}}", name = "test-service", ports = {"grpc": PortSpec(number=123, transport_protocol="TCP")})` require.Equal(t, expectedStr, service.String()) } func TestService_StringRepresentationWithApplicationProtocol(t *testing.T) { service, err := createTestServiceTypeWithApplicationProtocol() require.Nil(t, err) - expectedStr := `Service(hostname = "datastore-1", ip_address = "{{kurtosis:service_name.ip_address}}", ports = {"grpc": PortSpec(number=123, transport_protocol="TCP", application_protocol="http")})` + expectedStr := `Service(hostname = "datastore-1", ip_address = "{{kurtosis:service_name.ip_address}}", name = "test-service", ports = {"grpc": PortSpec(number=123, transport_protocol="TCP", application_protocol="http")})` require.Equal(t, expectedStr, service.String()) } @@ -79,7 +79,7 @@ func TestService_TestAttrNames(t *testing.T) { service, err := createTestServiceType() require.Nil(t, err) attrNames := service.AttrNames() - require.Equal(t, []string{hostnameAttr, ipAddressAttr, portsAttr}, attrNames) + require.Equal(t, []string{hostnameAttr, ipAddressAttr, serviceNameAttr, portsAttr}, attrNames) } func createTestServiceType() (*Service, error) { From ee864eda95373886795e6bab2e66835e021532e7 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Thu, 23 Mar 2023 14:56:33 +0100 Subject: [PATCH 3/4] added docs for the name property --- docs/docs/reference/starlark-instructions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/reference/starlark-instructions.md b/docs/docs/reference/starlark-instructions.md index cb6c3a0ff4..08644601eb 100644 --- a/docs/docs/reference/starlark-instructions.md +++ b/docs/docs/reference/starlark-instructions.md @@ -69,6 +69,7 @@ The `add_service` function returns a `service` object that contains service info - A `hostname` property representing [a future reference][future-references-reference] to the service's hostname. - An `ip_address` property representing [a future reference][future-references-reference] to the service's IP address. - A `ports` dictionary containing [future reference][future-references-reference] information about each port that the service is listening on. +- A `name` property representing the name of the service. The value of the `ports` dictionary is an object with three properties, `number`, `transport_protocol` and `application_protocol` (optional), which themselves are [future references][future-references-reference]. From fedbfa2852719585d5f61919d50a2a7ee4940be3 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Thu, 23 Mar 2023 15:02:07 +0100 Subject: [PATCH 4/4] added an integratio ntest --- .../golang/testsuite/startosis_test/startosis_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal_testsuites/golang/testsuite/startosis_test/startosis_test.go b/internal_testsuites/golang/testsuite/startosis_test/startosis_test.go index e16bcf4fa8..72564059a7 100644 --- a/internal_testsuites/golang/testsuite/startosis_test/startosis_test.go +++ b/internal_testsuites/golang/testsuite/startosis_test/startosis_test.go @@ -51,8 +51,8 @@ def run(plan, args): } ) - plan.add_service(service_name = DATASTORE_SERVICE_NAME, config = config) - plan.print("Service " + DATASTORE_SERVICE_NAME + " deployed successfully.") + result = plan.add_service(service_name = DATASTORE_SERVICE_NAME, config = config) + plan.print("Service " + result.name + " deployed successfully.") plan.exec( recipe = ExecRecipe( command = ["touch", FILE_TO_BE_CREATED],