@@ -11,6 +11,7 @@ import (
1111 "github.com/trento-project/agent/internal/core/cluster"
1212 "github.com/trento-project/agent/internal/core/cluster/cib"
1313 "github.com/trento-project/agent/internal/core/cluster/crmmon"
14+ mocksCluster "github.com/trento-project/agent/internal/core/cluster/mocks"
1415 mocksSystemd "github.com/trento-project/agent/internal/core/systemd/mocks"
1516 "github.com/trento-project/agent/pkg/utils/mocks"
1617 "github.com/trento-project/agent/test/helpers"
@@ -42,6 +43,9 @@ func (suite *ClusterTestSuite) TestNewClusterWithDiscoveryTools() {
4243 mockSystemd .On ("IsActive" , ctx , "corosync.service" ).Return (true , nil )
4344 mockSystemd .On ("IsActive" , ctx , "pacemaker.service" ).Return (true , nil )
4445
46+ mockCmdClient := new (mocksCluster.MockCmdClient )
47+ mockCmdClient .On ("GetState" , ctx ).Return ("S_IDLE" , nil )
48+
4549 c , err := cluster .NewClusterWithDiscoveryTools (ctx , & cluster.DiscoveryTools {
4650 CibAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_cibadmin.sh" ),
4751 CrmmonAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_crm_mon.sh" ),
@@ -51,13 +55,15 @@ func (suite *ClusterTestSuite) TestNewClusterWithDiscoveryTools() {
5155 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config" ),
5256 CommandExecutor : mockCommand ,
5357 SystemdConnector : mockSystemd ,
58+ CmdClient : mockCmdClient ,
5459 })
5560
5661 suite .Equal ("hana_cluster" , c .Name )
5762 suite .Equal ("47d1190ffb4f781974c8356d7f863b03" , c .ID )
5863 suite .Equal (false , c .DC )
5964 suite .Equal ("azure" , c .Provider )
6065 suite .Equal ("/dev/vdc;/dev/vdb" , c .SBD .Config ["SBD_DEVICE" ])
66+ suite .Equal ("idle" , c .State )
6167 suite .NoError (err )
6268}
6369
@@ -71,6 +77,9 @@ func (suite *ClusterTestSuite) TestNewClusterDisklessSBD() {
7177 mockSystemd .On ("IsActive" , ctx , "corosync.service" ).Return (true , nil )
7278 mockSystemd .On ("IsActive" , ctx , "pacemaker.service" ).Return (true , nil )
7379
80+ mockCmdClient := new (mocksCluster.MockCmdClient )
81+ mockCmdClient .On ("GetState" , ctx ).Return ("S_IDLE" , nil )
82+
7483 c , err := cluster .NewClusterWithDiscoveryTools (ctx , & cluster.DiscoveryTools {
7584 CibAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_cibadmin.sh" ),
7685 CrmmonAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_crm_mon_diskless_sbd.sh" ),
@@ -80,6 +89,7 @@ func (suite *ClusterTestSuite) TestNewClusterDisklessSBD() {
8089 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config_no_device" ),
8190 CommandExecutor : mockCommand ,
8291 SystemdConnector : mockSystemd ,
92+ CmdClient : mockCmdClient ,
8393 })
8494
8595 suite .Equal ("hana_cluster" , c .Name )
@@ -116,6 +126,7 @@ func (suite *ClusterTestSuite) TestNewClusterWithOfflineHost() {
116126 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config" ),
117127 CommandExecutor : mockCommand ,
118128 SystemdConnector : mockSystemd ,
129+ CmdClient : new (mocksCluster.MockCmdClient ),
119130 })
120131
121132 suite .Equal ("hana_cluster" , c .Name )
@@ -148,6 +159,7 @@ func (suite *ClusterTestSuite) TestNewClusterWithOfflineHostNoName() {
148159 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config" ),
149160 CommandExecutor : mockCommand ,
150161 SystemdConnector : mockSystemd ,
162+ CmdClient : new (mocksCluster.MockCmdClient ),
151163 })
152164
153165 suite .Equal ("" , c .Name )
@@ -156,6 +168,39 @@ func (suite *ClusterTestSuite) TestNewClusterWithOfflineHostNoName() {
156168 suite .NoError (err )
157169}
158170
171+ func (suite * ClusterTestSuite ) TestNewClusterWithUnknownState () {
172+ ctx := context .Background ()
173+ mockCommand := new (mocks.MockCommandExecutor )
174+ mockCommand .On ("Output" , "/usr/sbin/dmidecode" , "-s" , "chassis-asset-tag" ).
175+ Return ([]byte ("7783-7084-3265-9085-8269-3286-77" ), nil )
176+ mockCommand .On ("Output" , "/usr/sbin/sbd" , "-d" , "/dev/vdb" , "dump" ).Return (mockSbdDump (), nil )
177+ mockCommand .On ("Output" , "/usr/sbin/sbd" , "-d" , "/dev/vdb" , "list" ).Return (mockSbdList (), nil )
178+ mockCommand .On ("Output" , "/usr/sbin/sbd" , "-d" , "/dev/vdc" , "dump" ).Return (mockSbdDump (), nil )
179+ mockCommand .On ("Output" , "/usr/sbin/sbd" , "-d" , "/dev/vdc" , "list" ).Return (mockSbdList (), nil )
180+
181+ mockSystemd := new (mocksSystemd.MockSystemd )
182+ mockSystemd .On ("IsActive" , ctx , "corosync.service" ).Return (true , nil )
183+ mockSystemd .On ("IsActive" , ctx , "pacemaker.service" ).Return (true , nil )
184+
185+ mockCmdClient := new (mocksCluster.MockCmdClient )
186+ mockCmdClient .On ("GetState" , ctx ).Return ("" , errors .New ("" ))
187+
188+ c , err := cluster .NewClusterWithDiscoveryTools (ctx , & cluster.DiscoveryTools {
189+ CibAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_cibadmin.sh" ),
190+ CrmmonAdmPath : helpers .GetFixturePath ("discovery/cluster/fake_crm_mon.sh" ),
191+ CorosyncKeyPath : helpers .GetFixturePath ("discovery/cluster/authkey" ),
192+ CorosyncConfigPath : helpers .GetFixturePath ("discovery/cluster/corosync.conf" ),
193+ SBDPath : "/usr/sbin/sbd" ,
194+ SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config" ),
195+ CommandExecutor : mockCommand ,
196+ SystemdConnector : mockSystemd ,
197+ CmdClient : mockCmdClient ,
198+ })
199+
200+ suite .Equal ("unknown" , c .State )
201+ suite .NoError (err )
202+ }
203+
159204func (suite * ClusterTestSuite ) TestNewClusterCorosyncNotConfigured () {
160205 ctx := context .Background ()
161206 c , err := cluster .NewClusterWithDiscoveryTools (ctx , & cluster.DiscoveryTools {
@@ -167,6 +212,7 @@ func (suite *ClusterTestSuite) TestNewClusterCorosyncNotConfigured() {
167212 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config_no_device" ),
168213 CommandExecutor : new (mocks.MockCommandExecutor ),
169214 SystemdConnector : new (mocksSystemd.MockSystemd ),
215+ CmdClient : new (mocksCluster.MockCmdClient ),
170216 })
171217
172218 suite .Nil (c )
@@ -184,6 +230,7 @@ func (suite *ClusterTestSuite) TestNewClusterCorosyncNoAuthkeyConfigured() {
184230 SBDConfigPath : helpers .GetFixturePath ("discovery/cluster/sbd/sbd_config_no_device" ),
185231 CommandExecutor : new (mocks.MockCommandExecutor ),
186232 SystemdConnector : new (mocksSystemd.MockSystemd ),
233+ CmdClient : new (mocksCluster.MockCmdClient ),
187234 })
188235
189236 suite .Nil (c )
0 commit comments