@@ -26,6 +26,8 @@ import (
2626"time"
2727
2828"github.com/aws/aws-sdk-go-v2/aws"
29+ ecsservice"github.com/aws/aws-sdk-go-v2/service/ecs"
30+ "github.com/aws/aws-sdk-go-v2/service/ecs/types"
2931"github.com/golang/mock/gomock"
3032"github.com/stretchr/testify/assert"
3133"github.com/stretchr/testify/require"
@@ -44,8 +46,6 @@ import (
4446mock_ec2"github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"
4547ni"github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
4648"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
47- ecsservice"github.com/aws/aws-sdk-go-v2/service/ecs"
48- "github.com/aws/aws-sdk-go-v2/service/ecs/types"
4949)
5050
5151const (
@@ -480,6 +480,12 @@ func TestRegisterContainerInstance(t *testing.T) {
480480cfgAccessor .EXPECT ().External ().Return (true ).AnyTimes ()
481481},
482482},
483+ {
484+ name :"empty os detailed attribute" ,
485+ mockCfgAccessorOverride :func (cfgAccessor * mock_config.MockAgentConfigAccessor ) {
486+ cfgAccessor .EXPECT ().OSFamilyDetailed ().Return ("" ).AnyTimes ()
487+ },
488+ },
483489}
484490
485491for _ ,tc := range testCases {
@@ -508,6 +514,10 @@ func TestRegisterContainerInstance(t *testing.T) {
508514"ecs.outpost-arn" :outpostARN ,
509515cpuArchAttrName :getCPUArch (),
510516}
517+ // Add ecs.os-type-detailed only if OSFamilyDetailed() returns a non-empty value
518+ if tester .mockCfgAccessor .OSFamilyDetailed ()!= "" {
519+ expectedAttributes ["ecs.os-type-detailed" ]= tester .mockCfgAccessor .OSFamilyDetailed ()
520+ }
511521capabilities := buildAttributeList (fakeCapabilities ,nil )
512522platformDevices := []types.PlatformDevice {
513523{
@@ -553,12 +563,18 @@ func TestRegisterContainerInstance(t *testing.T) {
553563var expectedNumOfAttributes int
554564if ! tester .mockCfgAccessor .External () {
555565// 2 capability attributes: capability1, capability2
556- // and 5 other attributes:
557- // ecs.os-type, ecs.os-family, ecs.outpost-arn, my_custom_attribute, my_other_custom_attribute.
558- expectedNumOfAttributes = 7
566+ // Base attributes: ecs.os-type, ecs.os-family, ecs.outpost-arn, my_custom_attribute, my_other_custom_attribute (5)
567+ // Plus ecs.os-type-detailed if OSFamilyDetailed() is not empty
568+ expectedNumOfAttributes = 7 // 2 capabilities + 5 base attributes
569+ if tester .mockCfgAccessor .OSFamilyDetailed ()!= "" {
570+ expectedNumOfAttributes = 8
571+ }
559572}else {
560573// One more attribute for external case: ecs.cpu-architecture.
561574expectedNumOfAttributes = 8
575+ if tester .mockCfgAccessor .OSFamilyDetailed ()!= "" {
576+ expectedNumOfAttributes = 9
577+ }
562578}
563579
564580gomock .InOrder (
@@ -630,6 +646,7 @@ func TestRegisterContainerInstanceWithRetryNonTerminalError(t *testing.T) {
630646expectedAttributes := map [string ]string {
631647"ecs.os-type" :tester .mockCfgAccessor .OSType (),
632648"ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
649+ "ecs.os-type-detailed" :tester .mockCfgAccessor .OSFamilyDetailed (),
633650"my_custom_attribute" :"Custom_Value1" ,
634651"my_other_custom_attribute" :"Custom_Value2" ,
635652"ecs.availability-zone" :availabilityZone ,
@@ -725,6 +742,7 @@ func TestReRegisterContainerInstance(t *testing.T) {
725742expectedAttributes := map [string ]string {
726743"ecs.os-type" :tester .mockCfgAccessor .OSType (),
727744"ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
745+ "ecs.os-type-detailed" :tester .mockCfgAccessor .OSFamilyDetailed (),
728746"ecs.availability-zone" :availabilityZone ,
729747"ecs.outpost-arn" :outpostARN ,
730748}
@@ -749,8 +767,8 @@ func TestReRegisterContainerInstance(t *testing.T) {
749767resource ,ok := findResource (req .TotalResources ,"PORTS_UDP" )
750768assert .True (t ,ok ,`Could not find resource "PORTS_UDP"` )
751769assert .Equal (t ,"STRINGSET" ,* resource .Type ,`Wrong type for resource "PORTS_UDP"` )
752- // "ecs.os-type", ecs.os-family, ecs.outpost-arn and the 2 that we specified as additionalAttributes.
753- assert .Equal (t ,5 ,len (req .Attributes ),"Wrong number of Attributes" )
770+ // "ecs.os-type", ecs.os-family, ecs.os-type-detailed, ecs. outpost-arn and the 2 that we specified as additionalAttributes.
771+ assert .Equal (t ,6 ,len (req .Attributes ),"Wrong number of Attributes" )
754772reqAttributes := func ()map [string ]string {
755773rv := make (map [string ]string ,len (req .Attributes ))
756774for i := range req .Attributes {
@@ -821,6 +839,7 @@ func TestRegisterContainerInstanceWithEmptyTags(t *testing.T) {
821839expectedAttributes := map [string ]string {
822840"ecs.os-type" :tester .mockCfgAccessor .OSType (),
823841"ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
842+ "ecs.os-type-detailed" :tester .mockCfgAccessor .OSFamilyDetailed (),
824843"my_custom_attribute" :"Custom_Value1" ,
825844"my_other_custom_attribute" :"Custom_Value2" ,
826845}
@@ -886,8 +905,9 @@ func TestRegisterBlankCluster(t *testing.T) {
886905tester := setup (t ,ctrl ,mockEC2Metadata ,cfgAccessorOverrideFunc )
887906
888907expectedAttributes := map [string ]string {
889- "ecs.os-type" :tester .mockCfgAccessor .OSType (),
890- "ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
908+ "ecs.os-type" :tester .mockCfgAccessor .OSType (),
909+ "ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
910+ "ecs.os-type-detailed" :tester .mockCfgAccessor .OSFamilyDetailed (),
891911}
892912defaultCluster := tester .mockCfgAccessor .DefaultClusterName ()
893913gomock .InOrder (
@@ -935,8 +955,9 @@ func TestRegisterBlankClusterNotCreatingClusterWhenErrorNotClusterNotFound(t *te
935955tester := setup (t ,ctrl ,mockEC2Metadata ,cfgAccessorOverrideFunc )
936956
937957expectedAttributes := map [string ]string {
938- "ecs.os-type" :tester .mockCfgAccessor .OSType (),
939- "ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
958+ "ecs.os-type" :tester .mockCfgAccessor .OSType (),
959+ "ecs.os-family" :tester .mockCfgAccessor .OSFamily (),
960+ "ecs.os-type-detailed" :tester .mockCfgAccessor .OSFamilyDetailed (),
940961}
941962
942963defaultCluster := tester .mockCfgAccessor .DefaultClusterName ()